Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Seo Services company Manchester

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 08-12-2006, 01:17 AM
kenrose08 kenrose08 is offline
Registered User
 
Join Date: 17 Apr 2005
Posts: 7
kenrose08 is becoming part of the community
Help:Find and Display

Please Register to Remove these Ads

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.
Reply With Quote
  #2  
Old 08-12-2006, 07:10 PM
Tony James
Guest
 
Posts: n/a
Re: 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

Reply With Quote
  #3  
Old 08-12-2006, 07:25 PM
Tony James
Guest
 
Posts: n/a
Re: 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

Reply With Quote
  #4  
Old 08-13-2006, 12:08 AM
kenrose08 kenrose08 is offline
Registered User
 
Join Date: 17 Apr 2005
Posts: 7
kenrose08 is becoming part of the community
Thumbs up Thanks! another question

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!

Quote:
Originally Posted by Tony James

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


spotted a typo above: result.Row should be resultRng.Row
Reply With Quote
  #5  
Old 08-13-2006, 04:15 AM
Tony James
Guest
 
Posts: n/a
Re: Help:Find and Display

Insert the following in the If statement:

Else
MsgBox TextBox1.Text & " not found."

Reply With Quote
  #6  
Old 08-13-2006, 04:44 AM
kenrose08 kenrose08 is offline
Registered User
 
Join Date: 17 Apr 2005
Posts: 7
kenrose08 is becoming part of the community
Unhappy thanks!

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


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump