Hi!
I have a form, 2 textbox (textbox1 and text box2), and a button.
worksheet has column A and Column B.
ex.
column A column B
Item1 1,000
i want the button to search column A with the data i've entered in textbox1 and displays the corresponding value in column B in textbox2.
Have a look at the Find Method of the Range Object. There's an
example in the VBA help showing how to use it.
This could be useful!:
Private Sub cmdSearch_Click()
Set searchRng = Sheets(1).Range("A:A")
With searchRng
Set resultRng = .Find(TextBox1.Text, LookIn:=xlValues)
TextBox2.Text = TextBox2.Text & Sheets(1).Range("B" &
result.Row).Value & vbCrLf
> TextBox2.Text = TextBox2.Text & Sheets(1).Range("B" &
> result.Row).Value & vbCrLf
spotted a typo above: result.Row should be resultRng.Row
Thank you Sir,
this is so much help.
just another question.
what if the data i want to search is not in the list,
how do i code it?
thanks!
Originally Posted by Tony James
Insert the following in the If statement:
Else
MsgBox TextBox1.Text & " not found."
thanks
but how do i start the if statement?
i really dont know how and where to code it
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks