ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help:Find and Display (https://www.excelbanter.com/excel-programming/370178-help-find-display.html)

kenrose08[_4_]

Help:Find and Display
 

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*.


--
kenrose08
------------------------------------------------------------------------
kenrose08's Profile: http://www.excelforum.com/member.php...o&userid=22317
View this thread: http://www.excelforum.com/showthread...hreadid=570977


Tony James[_2_]

Help:Find and Display
 
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


Tony James[_2_]

Help:Find and Display
 


TextBox2.Text = TextBox2.Text & Sheets(1).Range("B" &
result.Row).Value & vbCrLf


spotted a typo above: result.Row should be resultRng.Row


kenrose08[_5_]

Help:Find and Display
 

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*!

Tony James Wrote:

TextBox2.Text = TextBox2.Text & Sheets(1).Range("B" &
result.Row).Value & vbCrLf


spotted a typo above: result.Row should be resultRng.Row



--
kenrose08
------------------------------------------------------------------------
kenrose08's Profile: http://www.excelforum.com/member.php...o&userid=22317
View this thread: http://www.excelforum.com/showthread...hreadid=570977


Tony James[_2_]

Help:Find and Display
 
Insert the following in the If statement:

Else
MsgBox TextBox1.Text & " not found."


kenrose08[_7_]

Help:Find and Display
 

thanks
but how do i start the if statement?
i really dont know how and where to code it


--
kenrose08
------------------------------------------------------------------------
kenrose08's Profile: http://www.excelforum.com/member.php...o&userid=22317
View this thread: http://www.excelforum.com/showthread...hreadid=570977



All times are GMT +1. The time now is 11:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com