Solved

Unable to get the Search property of the WorksheetFunction Class

Posted on 2014-02-12
3
1,431 Views
Last Modified: 2014-02-13
Hello Experts,

I have a macro kindly written by byundt which is designed to look at a column E which contains a message.  The macro would then search through the message cell and extract each of the lines and then put them into columns under the correct headings.

When I now run the macro I keep getting the "Unable to get the Search property of the WorksheetFunction Class".  I have worked out that it is caused by running into a blank cell.  

Could anyone help me configure the macro to move on if encountering any blank cells?  I have tried to figure out a way myself but just end up breaking the macro completely.

I have attached an example of the macro and data for your review.

Regards,
InfoSec36
WorksheetFunction-Class-error.xls
0
Comment
Question by:infosec36
3 Comments
 
LVL 19

Assisted Solution

by:Ken Butters
Ken Butters earned 100 total points
Comment Utility
created new variable to know if we had empty cell
Dim EmptyCell As Boolean

Open in new window

added the following code around the worksheet function (in 2 places)
                    On Error Resume Next
                    j = Application.WorksheetFunction.Search("detailed authentication information:", s, i)
                    If Err = 0 Then
                        emtpyCell = False
                    Else
                        EmptyCell = True
                    End If
                    On Error GoTo 0

Open in new window

then modified this line to check for empty cell:
If Not EmptyCell Then: targ.Cells(n, k).Value = Trim(Mid$(s, i, j - i))

Open in new window


Attached update file
WorksheetFunction-Class-error.xls
0
 
LVL 80

Accepted Solution

by:
byundt earned 400 total points
Comment Utility
If you use Application.Search (instead of Application.WorksheetFunction.Search) and return the result to a Variant, it won't matter if SEARCH returns an error value. Nor will you need to turn error handling off.
Sub ParseAD_Report()
Dim cel As Range, rg As Range, targ As Range
Dim vHeaders As Variant
Dim s As String, s2 As String
Dim k As Long, n As Long, nHeaders As Long
Dim i As Variant, j As Variant
Application.ScreenUpdating = False
With Worksheets("Formatted")
    Set rg = .Range("E2")       'First cell with data
    Set rg = .Range(rg, .Cells(.Rows.Count, rg.Column).End(xlUp))
End With
With Worksheets("Formatted2")
    Set targ = .Range("A1")     'First header label
    Set targ = .Range(targ, .Cells(1, .Columns.Count).End(xlToLeft))    'All the header labels
    vHeaders = targ.Value
    nHeaders = targ.Columns.Count
    n = .UsedRange.Rows.Count
End With
For Each cel In rg.Cells
    s = cel.Value
    If s <> "" Then
        n = n + 1
        j = 1
        For k = 1 To nHeaders
            If vHeaders(1, k) <> "" Then
                i = Application.Search(vHeaders(1, k), s, j) + Len(vHeaders(1, k))
                If Not IsError(i) Then
                    If k = nHeaders Then
                        j = Application.Search("detailed authentication information:", s, i)
                    Else
                        s2 = vHeaders(1, k + 1)
                        If s2 = "" Then
                            s2 = vHeaders(1, k + 2)
                        End If
                        j = Application.Search(s2, s, i)
                    End If
                End If
                If (Not IsError(i)) And (Not IsError(j)) Then targ.Cells(n, k).Value = Trim(Mid$(s, i, j - i))
            End If
        Next
    End If
Next
End Sub

Open in new window

0
 

Author Closing Comment

by:infosec36
Comment Utility
Thank you both very much for your help.

Byndt, works perfectly as usual.  Thank you.

Ken,  I will be able to utilise your solution in my other analysis worksheet.

Regards,
InfoSec36
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now