Thread: finding
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default finding

Assign this to a commandbutton on your userform: works with string or numbers....

Private Sub CommandButton1_Click()
Dim c As Range
Dim strF1 As String
Dim strF2 As String
Dim strAdd As String

strF1 = UserForm1.TextBox1.Text
strF2 = UserForm1.TextBox2.Text

With ActiveSheet.Range("A:A")
Set c = .Find(strF1, LookIn:=xlValues, lookAt:=xlWhole)

If Not c Is Nothing Then
strAdd = c.Address
If c(1, 2).Value = strF2 Then GoTo Notify
Else:
MsgBox "Not Found"
Exit Sub
End If

Set c = .FindNext(c)
If Not c Is Nothing And c.Address < strAdd Then
Do
If c(1, 2).Value = strF2 Then GoTo Notify
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < strAdd
End If
End With

Notify:
MsgBox """" & strF1 & """ is next to """ & _
strF2 & """ in cells " & c.Resize(1, 2).Address

End Sub

HTH,
Bernie
MS Excel MVP


"enyaw" wrote in message
...
I have two textboxes on a form. I want to be able to use textbox1 to search
column A and textbox2 to search columnB. I need to be able to search and
find the two numbers but the numbers have to be in the same row. Anyone got
any ideas?