hi guys,

I have a form-based solution for users to store data and one of the functions is FindNext. Users put in a last name in the textbox (txt_lastname) and click on the button.


Private Sub btn_findNext_LN_admin_Click()
Dim fndRngLastName As Range
Dim recCLastName As Variant
recCLastName = Application.WorksheetFunction.CountIf(Worksheets("Data").Range("B:B"), Me.txt_lastname.Value)

''Columns("B:B").Select
Set fndRngLastName = Cells.Find(what:=Me.txt_lastname.Value, after:=Worksheets("Data").Range("B1"), LookIn:=xlValues, LookAt _
       :=xlWhole, SearchOrder:=xlByRows, searchdirection:=xlNext, MatchCase:= _
       False, SearchFormat:=False)
       
       If Not fndRngLastName Is Nothing Then
         Dim xLastName As Variant
         For xLastName = 1 To recCLastName
            Me.txt_lastname = ActiveCell.Value
         Next
            Cells.FindNext(after:=ActiveCell).Activate
The first part of the code counts # of occurrences this last name exists in column B. The second part is the findnext...

This code functions well, except if the last name you are searching for also exists in another column, and I want the search done on column B ONLY. I thought that you would just select the specific column as I did in the code(commented out part), but this is not enough and I am stuck.

Can someone help me and point me in the right direction? What am I missing here?

Thanks