View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default THE "INSTR" FUNCTION !!!

The InStr function has a strange syntax in that it has an optional first and
fourth argument (an optional first argument is very unusual). Normally, one
uses the default values for the optional arguments (specifying only the text
to search and the string to look for). The first argument can be specified
if need be without having to specify the fourth argument; HOWEVER, if you
plan to specify the fourth argument, you MUST specify the first one as well.
So, as Jacob posted, your statement needs to look like this...

If InStr(1, ComboBox5.Value, TextBox1.Value, vbBinaryCompare) 0 Then.

I would note that, UNLESS you used an Option Compare statement in your code
module to change it, Binary comparisons are the default meaning that you
would not have to explicitly specify vbBinaryCompare to get a Binary
comparison. So, if you don't have an Option Compare statement active, you
should be able to just do this...

If InStr(ComboBox5.Value, TextBox1.Value) 0 Then

--
Rick (MVP - Excel)


"jay dean" wrote in message
...
Hello -

Both combobox5 and textbox1 contain text strings. I am trying to
determine if the string selected from the dropdown list in combobox5 is
found in textbox1. If I use the following statement:

If InStr(ComboBox5.Value, TextBox1.Value, vbBinaryCompare) 0 then ....

I get the error: "Type mismatch."
Any help with a better statement would be appreciated.

Thanks!
Jay

*** Sent via Developersdex http://www.developersdex.com ***