View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Paul D Byrne[_2_] Paul D Byrne[_2_] is offline
external usenet poster
 
Posts: 5
Default Iserror with Search

Thanks Dave - that's right, however with the other example if you do
?IsError(Application.WorksheetFunction.Search("*Va lue*Date*", "System Date",
1))

you don't get True, but a Run-Time Error 1004, the question is, why doesn't
the IsError function trap the Run-Time Error 1004 and return True (it is an
error after all!).

cheers.

Paul.

--
Paul Byrne


"Dave Peterson" wrote:

I see False when I do this in the immediate window.

?IsError(Application.WorksheetFunction.Search("*Va lue*Date*", "Value Date", 1))
False

And this returned False:
MsgBox IsError(Application.WorksheetFunction _
.Search("*Value*Date*", "Value Date", 1))

But VBA has its own version of application.search. Look at InStr() in VBA's
help.



Paul D Byrne wrote:

Hi,

I am trying to test a string in VBA to see if it exists using the following :
Iserror(Application.WorksheetFunction.Search("*Val ue*Date*", "System Date",
1))

If I use the msgbox in the immediate pane to see the result I get
Run-time error '1004':
Unable to get the Search property of the WorksheetFunction class

However using the following:
Iserror(Application.WorksheetFunction.Search("*Val ue*Date*", "Value Date", 1))

evaluates to 'False' - which is what I expect.

Howcome the first statement does not evaluate to True?

thanks,

Paul B.
PS : The 2nd parameter will be a variable in production - using the words is
only for development.


--

Dave Peterson