Consulting

Results 1 to 7 of 7

Thread: Userform Search Option

  1. #1

    Userform Search Option

    I have a userform with Fourfields. The field names are Project Name, Project Number, Analyst Name and Search Field. I would like to use the search field on this form using VBA which will search either of the remaining three fields based on the text or numeric entry in the Search Field. Any assistance is greatly appreciated. Thank you in advance.

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi brorick,

    What kind of fields do you have? Are they TextBoxes? Do you mean you want to (if TextBoxes) search the other TextBoxes for that value? Can you upload a zipped copy of a spreadsheet with your userform in it?

  3. #3
    Thank you for your response. I was hypothetically speaking about the form as I have not yet created it. I have sketched out the idea and the logic. I just can't seem to create the logic behind the search capability. In response to your question, I would like the field to search either a text or numeric field, if possible. Therefore, if I wanted to search by project name or project number I could do so. Lets say, Project Name (text) is in column A, Project Number(Numeric) is in column B, Analyst Name(text) is in column C. Thanks again.

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You can search usind Find in VBA:

    Dim Cel As Range
    Set Cel = Sheets("Sheet1").Range("A:A").Find(What:=SearchTerm)

  5. #5
    Thank you FireFyTr and DRJ for your assistance. I really do appreciate your help. I will give this recommendation a try. Just a quick question. Do I place this code within the Search Field and then activate it based on a button? Thanks again.

  6. #6
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    This would be inside of a Standard Module (Alt + F11, Insert, Module)

    Sub myTest()
        Dim Cel As Range
        Set Cel = Sheets("Sheet1").Range("A:A").Find(What:=SearchTerm)
    End Sub
    Remember, with the Find method, you always start it out using the range you want to search; this screws people up sometimes and they get it backwards. To check if you found anything in your Cel variable, do a check after your search, something like ...

    If Not Cel Is Nothing Then
        'Do stuff here
    End If

  7. #7
    Thanks again. You guys are a great source. I will give it a try.

Posting Permissions

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