Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Iserror with Search

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Iserror with Search

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Iserror with Search

The Wild Card * is confusing Excel. The code is looking at two strings
"Value Date" and "System Date". the code below will always return a false
because the string "Value Date" cannot be found inside of "System Date". I
think you want variable in the string or you want the following

Iserror(Application.WorksheetFunction.Search(Range ("Value Date"),
Range("System Date"), 1))

The code abovewill look at the named range in your worksheet.


"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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Iserror with Search

Hi Joel, thanks for taking the time to reply.

The issue is why the IsError isn't trapping the returned error value and
displaying True. It's not a named range I'm using, in the example I just want
the Search function to fail and the IsError to return True. When i can get
this working I will search a string variable instead of "System Date".

try the following :
?IsError(Application.WorksheetFunction.Search("*Va lue*Date*", "Value Date",
1))
displays False in the immediate window
?IsError(Application.WorksheetFunction.Search("Val ue Date", "System Date", 1))
gives a Run-Time error 1004 when i am expecting True.

- I have taken out the wildcards and still get the same result.
cheers,

Paul B.
--
Paul Byrne


"Joel" wrote:

The Wild Card * is confusing Excel. The code is looking at two strings
"Value Date" and "System Date". the code below will always return a false
because the string "Value Date" cannot be found inside of "System Date". I
think you want variable in the string or you want the following

Iserror(Application.WorksheetFunction.Search(Range ("Value Date"),
Range("System Date"), 1))

The code abovewill look at the named range in your worksheet.


"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

  #5   Report Post  
Posted to microsoft.public.excel.programming
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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Iserror with Search

I don't think Search will ever Error. Do a test and check if Search returns
zero which indicated the string is not found. If the string is found the
return value is a number which indicates the character position of where the
1st character of the string is found

if (Application.WorksheetFunction.Search("*Value*Date *", "System Date",
1) = 0)


"Paul D Byrne" wrote:

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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Iserror with Search

The =search() worksheet function returns an error.

It sounds like you're confusing it with VBAs InStr.



Joel wrote:

I don't think Search will ever Error. Do a test and check if Search returns
zero which indicated the string is not found. If the string is found the
return value is a number which indicates the character position of where the
1st character of the string is found

if (Application.WorksheetFunction.Search("*Value*Date *", "System Date",
1) = 0)


"Paul D Byrne" wrote:

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


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Iserror with Search

There are some differences in the way excel's VBA handles .worksheetfunction.

For instance, application.vlookup() and application.match() can be checked with
iserror.

But application.worksheetfunction.vlookup() and
application.worksheetfunction.match() both cause runtime errors.

The same is true with the differences between application.search() and
application.worksheetfunction.search().

Do I know why? Nope.

Does it matter which syntax you use? Yep.

But outside of the academic reasons for using
application.search/application.worksheetfunction.search, I still think that
InStr is a better solution here.


Paul D Byrne wrote:

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


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Iserror with Search

Just to add, you could use this kind of thing:

on error resume next
msgbox application.worksheetfunction.search(...)
if err.number < 0 then
'not found
err.clear
else
'found
end if
on error goto 0

But using iserror(application.search(...)) is easier.

And VBA's InStr is even easier (have I said that enough????) <vbg

Dave Peterson wrote:

There are some differences in the way excel's VBA handles .worksheetfunction.

For instance, application.vlookup() and application.match() can be checked with
iserror.

But application.worksheetfunction.vlookup() and
application.worksheetfunction.match() both cause runtime errors.

The same is true with the differences between application.search() and
application.worksheetfunction.search().

Do I know why? Nope.

Does it matter which syntax you use? Yep.

But outside of the academic reasons for using
application.search/application.worksheetfunction.search, I still think that
InStr is a better solution here.

Paul D Byrne wrote:

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


--

Dave Peterson


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Iserror with Search

Hi,

this is what I ended up using :

If InStr(1, acell.Cells(1, j + 1).Value, "Value", 1) 0 And InStr(1,
acell.Cells(1, j + 1).Value, "Date", 1) 0 Then

intDateCol = acell(0, j + 1).Column

ElseIf InStr(1, acell.Cells(1, j + 1).Value, "End", 1) 0 And InStr(1,
acell.Cells(1, j + 1).Value, "Date", 1) 0 Then

intDateCol = acell(0, j + 1).Column

End If

thanks for the help guys.

Paul B.



"Dave Peterson" wrote:

Just to add, you could use this kind of thing:

on error resume next
msgbox application.worksheetfunction.search(...)
if err.number < 0 then
'not found
err.clear
else
'found
end if
on error goto 0

But using iserror(application.search(...)) is easier.

And VBA's InStr is even easier (have I said that enough????) <vbg

Dave Peterson wrote:

There are some differences in the way excel's VBA handles .worksheetfunction.

For instance, application.vlookup() and application.match() can be checked with
iserror.

But application.worksheetfunction.vlookup() and
application.worksheetfunction.match() both cause runtime errors.

The same is true with the differences between application.search() and
application.worksheetfunction.search().

Do I know why? Nope.

Does it matter which syntax you use? Yep.

But outside of the academic reasons for using
application.search/application.worksheetfunction.search, I still think that
InStr is a better solution here.

Paul D Byrne wrote:

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


--

Dave Peterson


--

Dave Peterson



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If IsError Help Karin Excel Discussion (Misc queries) 1 September 21st 09 09:04 PM
=IF(ISERROR(SEARCH("insurance",A125,1)),"","*") cynichromantique Excel Worksheet Functions 9 September 25th 08 09:49 PM
IsError error on Search MFINE Excel Discussion (Misc queries) 6 August 28th 07 05:26 PM
IF ISERROR John Moore Excel Discussion (Misc queries) 5 June 26th 06 02:01 PM
ISERROR - #NAME? Mpaul Excel Worksheet Functions 2 February 20th 06 10:27 PM


All times are GMT +1. The time now is 11:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"