S
S Shipley
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
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