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

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Help with Instr function

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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"JMay" wrote in message
...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Help with Instr function

Sorry but even after changing
If Temp 0 Then to
If T 0 Then

I still get same result,,

grrrrrrrr


"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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Help with Instr function

Thanks Don,,

"Don Guillett" wrote:

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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"JMay" wrote in message
...
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





  #7   Report Post  
Posted to microsoft.public.excel.programming
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
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
Help with VBA InStr() function EagleOne Excel Discussion (Misc queries) 10 April 12th 07 02:47 PM
InStr function AshGrant Excel Programming 7 July 28th 06 10:25 AM
InStr Function zoot Excel Programming 1 June 5th 06 03:53 AM
InStr Function Question gfh28105 Excel Programming 3 September 14th 05 02:28 AM
InStr function question [email protected] Excel Programming 9 June 28th 05 03:03 PM


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

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

About Us

"It's about Microsoft Excel"