hi,
I'm back again. I was able to get some help here before and Im hoping for another answer to my question. I need help with the code I have below. Actually the code was also taken from some of the threads I was able to read here. I need help in moving the active cell to the matched search data found. Currently the code below does not move the active cell to the matched searched data. Say, if a user will type employee id, once the user click the find button, it will return a value from the label I have but will not move the active cell to the matched or searched data. Please help me move the active cell to the matched searched entry. Thanks
Private Sub cmdfind_Click()
'FIND BUTTON
Dim MatchCell As Range
Dim strFind, FirstAddress As String 'what to find
Dim rSearch As Range 'range to search
Dim f As Integer
'Search Range is the ID numbers column
Set rSearch = ActiveSheet.Range("A1", Cells(Rows.Count, "A").End(xlUp))
'ID number to find
strFind = TextBox1.Value
'Allways set All the Named Argumnets for the First Search.
'The system "Find" function uses these settings also.
With rSearch
Set MatchCell = .Find(What:=strFind, _
After:=Cells(1, 1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not MatchCell Is Nothing Then 'found it
'load entry to form
Label1.Caption = MatchCell.Offset(0, 1).Value 'Employee name
FirstAddress = MatchCell.Address
CurRow = MatchCell.Row
'Check for and count duplicate entries
Do
f = f + 1 'count number of matching records
Set MatchCell = .FindNext(MatchCell)
Loop While Not MatchCell Is Nothing And MatchCell.Address <> FirstAddress
If f > 1 Then
MsgBox "There are " & f & " instances of " & strFind
Me.Height = 318
End If
Else
MsgBox strFind & " not listed" 'search failed
End If
End With
End Sub
Cheers,
Stoey
Bookmarks