PDA

View Full Version : [SOLVED:] Userform Search Option



brorick
11-04-2004, 02:20 PM
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.

Zack Barresse
11-04-2004, 02:28 PM
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?

brorick
11-04-2004, 02:45 PM
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.

Jacob Hilderbrand
11-04-2004, 06:24 PM
You can search usind Find in VBA:


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

brorick
11-05-2004, 06:36 AM
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.

Zack Barresse
11-05-2004, 09:26 AM
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

brorick
11-05-2004, 11:46 AM
Thanks again. You guys are a great source. I will give it a try.