Unable to get the Search property of the WorksheetFunction class.

rjn2002

New Member
Joined
Feb 23, 2009
Messages
8
I am having trouble with IsError function consistently catching errors in my call to the Search worksheetfunction. For example, here is a snippet of my code that works just fine:

Code:
If IsError(Application.WorksheetFunction.Search("__*-DEFERRED", netName)) Then
            If IsError(Application.WorksheetFunction.Search("__* Due", netName)) Then
                If IsError(Application.WorksheetFunction.Search(" TOTDUEINT ", netName)) Then
                    If IsError(Application.WorksheetFunction.Search(" ARREARS ", netName)) Then...
However, later in my code I have:

Code:
tempNetName = UCase(Trim(Sheet1.Range("netLIBOR").Offset(yG, xR)))
    
    If IsError(Application.WorksheetFunction.Search(" DUE FROM ", tempNetName)) Then...
This gives me the following error: "Run-time error '1004': Unable to get the Search property of the WorksheetFunction class."

Furthermore, here is the entire piece of code that is giving me problems currently. I have commented out the line where I use the InStr function, which works fine. Then all of the following calls to the Search function work fine as well; however in its current state, I get the error mentioned above. The variables "tempNetName" and "netName" are both earlier defined as Strings and are returning valid strings to be evaluated.

Code:
    If IsError(Application.WorksheetFunction.Search(" DUE FROM ", tempNetName)) Then
    'If InStr(1, tempNetName, " DUE FROM ", vbTextCompare) = 0 Then
            'do nothing
    Else
        netName = ReturnLastWord(Sheet1.Range("netLIBOR").Offset(yG, xR))
        edgeName = Application.WorksheetFunction.VLookup(netName, Sheet3.Range("tokenTable"), 2, 0)
        lineType = "DUE"
        endOfCode = " Due from " & edgeName
        netName = UCase(Trim(Sheet1.Range("netLIBOR").Offset(yG, xR)))
        If IsError(Application.WorksheetFunction.Search("__*-DEFERRED", netName)) Then
            If IsError(Application.WorksheetFunction.Search("__* Due", netName)) Then
                If IsError(Application.WorksheetFunction.Search(" TOTDUEINT ", netName)) Then
                    If IsError(Application.WorksheetFunction.Search(" ARREARS ", netName)) Then
                        'If IsError(Application.WorksheetFunction.Search(" PRINCIPAL ", netName)) Then
                        'must be principal
                        edgeName = "T_" & ReturnFirstWord(netName) & "_Principal" & endOfCode
                    Else
                        'if it's Arrears
                        edgeName = "T_" & ReturnFirstWord(netName) & "_i_Deferred" & endOfCode
                    End If
                Else
                    'totdueint
                    edgeName = "T_" & ReturnFirstWord(netName) & "_i_Paid" & endOfCode
                End If
            Else
                'it's hedge or fee due. currently assumes a fee
                edgeName = "F_" & Mid(netName, 3, Application.WorksheetFunction.Search(" Due", netName) - 3) & "_Paid" & endOfCode
            End If
        Else
            'fee or hedge deferred.  currently assumes a fee
            edgeName = "F_" & Mid(netName, 3, Application.WorksheetFunction.Search("-Deferred", netName) - 3) & "_Deferred" & endOfCode
        End If
            
    End If

I know that it is not good to rely on worksheet functions too much, but this is more of a general question as to why it's not working consistently all through my code.
 
Glad to help. Just goes to show that although On Error Resume Next can be useful, it's also a dangerous beastie! :)
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top