i have an excel sheet the has column A which the search value will be in , and it should retrieve results from column B,the code should whenever I enter a value in textbox (txtreg) get results in Listbox (txtledglist) which might be 1 result or more up to 6 .
the code that I have is this: whenever I type the search value that has just 1 result brings it fine, but when it has multiple results it gets it but takes over 5 min and somtimes excel crashes which is really unsuall. or when I delete the search value to try and enter a new one it also craches , when I check the VBA I see that the code keeps running which is causing the excel to crash.
any ideas to make the code simpler or what am I doing wrong?
thanks.
Private Sub txtreg_Change()


    Dim wb As Workbook
    Dim ws As Worksheet
    Dim lookupValue As String
    Dim results() As Variant
    Dim rng As Range
    Dim cell As Range
    Dim index As Long
    Dim count As Long
    

    Set wb = ThisWorkbook
    Set ws = wb.Sheets("L 403")
    

    lookupValue = txtreg.Value
    
    txtledglist.Clear
    
    Set rng = ws.Range("A:B")
    On Error Resume Next
    Set cell = rng.Columns(1).Find(What:=lookupValue, LookIn:=xlValues, LookAt:=xlWhole)
    On Error GoTo 0
    
    If Not cell Is Nothing Then
        count = 0
        Do
            count = count + 1
            ' Find the next match
            Set cell = rng.Columns(1).FindNext(cell)
        Loop While Not cell Is Nothing And cell.Address <> rng.Columns(1).Find(What:=lookupValue, After:=cell, LookIn:=xlValues, LookAt:=xlWhole).Address
        
        ReDim results(1 To count)
        
        Set cell = rng.Columns(1).Find(What:=lookupValue, LookIn:=xlValues, LookAt:=xlWhole)
        
        index = 1
        Do
            results(index) = rng.Columns(2).Cells(cell.Row - rng.Cells(1).Row + 1).Value ' Adjusting for header row
            index = index + 1
            Set cell = rng.Columns(1).FindNext(cell)
        Loop While Not cell Is Nothing And cell.Address <> rng.Columns(1).Find(What:=lookupValue, After:=cell, LookIn:=xlValues, LookAt:=xlWhole).Address
        
        txtledglist.List = results
       
    End If

End Sub


find values on a user form from text box and results shown on a List box
First of all, you should save the first cell you found, so that you don't have to call .Find again, which would restart the search. Also, you don't need to compare against Nothing in the loop condition.
Second, I don't clearly understand the line with the comment "Adjusting for header row". Anyway, there is no adjustment necessary: the two cells are in the same row.
The corrected code:
Private Sub txtreg_Change()
    Dim lookupValue As String: lookupValue = txtreg.Value
    Dim wb As Workbook: Set wb = ThisWorkbook
    Dim ws As Worksheet: Set ws = wb.Sheets("L 403")
    
    txtledglist.Clear
    
    Dim rng As Range: Set rng = ws.Range("A:B")
    On Error Resume Next
    Dim firstCell As Range: Set firstCell = rng.Columns(1).Find(What:=lookupValue, LookIn:=xlValues, LookAt:=xlWhole)
    On Error GoTo 0
    
    If Not firstCell Is Nothing Then
        Dim cell As Range: Set cell = firstCell
        Dim count As Long: count = 0
        Do
            count = count + 1
            Set cell = rng.Columns(1).FindNext(cell)
        Loop While cell.Address <> firstCell.Address
        
        Dim results() As Variant: ReDim results(1 To count)
        
        Set cell = rng.Columns(1).Find(What:=lookupValue, LookIn:=xlValues, LookAt:=xlWhole)
        
        Dim index As Long: index = 1
        Do
            results(index) = rng.Cells(cell.Row, 2).Value
            index = index + 1
            Set cell = rng.Columns(1).FindNext(cell)
        Loop While cell.Address <> firstCell.Address
        
        txtledglist.List = results
    End If
End Sub

I don't exactly know your whole application but may be it is worth avoiding .Find and .FindNext.
