I'm using Excel 2013 with Windows 7.
I have a user form with a text box named 'TextBox_SearchValue' that accepts a user entered search string. The form also has one button to begin the search. If I use the SearchStartLocation variable as an argument value for 'After:=' in my Find method (as in the below code), it results in error message "Run-time error '13': Type mismatch".
If, however, I hard code "Cells(1, 1)" or "ActiveCell" as a value for 'After:=' the Find method runs without error.
Why is the SearchStartLocation variable not being accepted?
Private SearchStartLocation As String
Private Sub UserForm_Initialize()
SearchStartLocation = "Cells(1, 1)"
End Sub
Private Sub SearchButton_Click()
Cells.Find(What:=TextBox_SearchValue.Text, After:=SearchStartLocation, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
SearchStartLocation = "ActiveCell"
End Sub
I have a user form with a text box named 'TextBox_SearchValue' that accepts a user entered search string. The form also has one button to begin the search. If I use the SearchStartLocation variable as an argument value for 'After:=' in my Find method (as in the below code), it results in error message "Run-time error '13': Type mismatch".
If, however, I hard code "Cells(1, 1)" or "ActiveCell" as a value for 'After:=' the Find method runs without error.
Why is the SearchStartLocation variable not being accepted?
Private SearchStartLocation As String
Private Sub UserForm_Initialize()
SearchStartLocation = "Cells(1, 1)"
End Sub
Private Sub SearchButton_Click()
Cells.Find(What:=TextBox_SearchValue.Text, After:=SearchStartLocation, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
SearchStartLocation = "ActiveCell"
End Sub