View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Help with Instr function

Two problems...

T = InStr(1, Z, ActiveSheet.Range("A1"), vbTextCompare)
should be:
T = InStr(1, ActiveSheet.Range("A1").value, Z, vbTextCompare)
(I like to use .value!)

And don't check
If Temp 0 then
you want
If T 0 then


JMay wrote:

In cell A1 I have: The Sky is blue
In the input box I enter blue
After running the below (99 times) i get - Didn't Find it! - 99 times !!!

Why?

Sub Foo()
Dim T As Integer
Dim Z As String
Z = InputBox("Enter key word") 'enter blue
T = InStr(1, Z, ActiveSheet.Range("A1"), vbTextCompare)
If Temp 0 Then
MsgBox "Found it!"
Else
MsgBox "Didn't Find it!"
End If
End Sub


--

Dave Peterson