+ Reply to Thread
Results 1 to 6 of 6

Help:Find and Display

  1. #1
    Registered User
    Join Date
    04-17-2005
    Posts
    7

    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.

  2. #2
    Tony James
    Guest

    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


  3. #3
    Tony James
    Guest

    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


  4. #4
    Registered User
    Join Date
    04-17-2005
    Posts
    7

    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

  5. #5
    Tony James
    Guest

    Re: Help:Find and Display

    Insert the following in the If statement:

    Else
    MsgBox TextBox1.Text & " not found."


  6. #6
    Registered User
    Join Date
    04-17-2005
    Posts
    7

    Unhappy thanks!

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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1