Hi I am using a search function on a userform and want the ID entered in the textbox to search for everything in Column B. If the value is found then it will display in the other textboxes - this bit works for me.
What doesn't is if the value is Not found then show msgbox to say "value not found".
Bit in bold is what's not working. When I run the sub first condition works but then it doesn't look for the value i enter and nor does it return those that exist.
Any help with this will be greatly appreciated
What doesn't is if the value is Not found then show msgbox to say "value not found".
VBA Code:
Private sub searchbutton_click()
Dim ID_ref as string
ID_ref = trim(search box.text)
Lastrow =worksheets("Admin").cells(Rows.count, 2).End(club).Row
If Trim(ID_ref) ="" Then
Magbox"search field is blank"
End if
Exit sub
[B]If trim(worksheets("admin").cells(i, 2) <> Trim(ID_ref) Then
Msgbox "item not found"
End if
Exit sub[/B]
If trim(worksheets("admin").cells(i, 2) = Trim(ID_ref) Then
Type.text = worksheets("admin").cells(i,4).value
Exit for
End if
Next
End sub
Bit in bold is what's not working. When I run the sub first condition works but then it doesn't look for the value i enter and nor does it return those that exist.
Any help with this will be greatly appreciated