LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Find using a variable value

I trying to create a small macro to look up a value typed in a textbox using
the following code. If I try to set the variable S to the value of TextBox1
the find does not return anything. If I set S to the actual value then the
find is successful.

Private Sub CommandButton1_Click()
Dim strRange As String
Dim strMyString As String
Dim rngFound As Range
MyString = TextBox1.Value
Set rngFound = Sheets("Dealership Report").Cells.Find(MyString, , ,
xlPart)

' TextBox1.Value = 240599 , actual value entered in text box
S = TextBox1.Value
Set SearchRange = Worksheets("sheets 1").Range("A1:A3671")
Set c = SearchRange.Find(What:=S, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If c Is Nothing Then
MsgBox "Not found"
Else
strRange = c.Address
Range(strRange).Activate
MsgBox "Found"
End If
End Sub

 
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
Variable Find Joe Murphy[_2_] Excel Discussion (Misc queries) 1 January 7th 09 02:21 PM
3 variable find and replace ncspndoc Excel Discussion (Misc queries) 4 June 30th 06 09:07 PM
Find with a variable Chris Excel Programming 3 January 19th 06 03:03 AM
Find a variable ben Excel Programming 6 December 1st 04 07:27 PM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


All times are GMT +1. The time now is 01:32 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"