View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Help with Instr function

On Sun, 7 Sep 2008 11:38:01 -0700, 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


Another reason to always include Option Explicit in your VBA routines.

From the menu bar:
Tools/Options
Editor
Select: Require Variable Declaration
--ron