Simple user form help

Rick50

New Member
Joined
Feb 26, 2010
Messages
17
I am a VBA novice. I am trying to create a user form that performs a search and returns cell values (mostly text) from an excel spreadsheet that is not already open.
The user form would have 1 box for the user to enter (type in) what they are looking for. They would then hit a search button. And It would populate 3 other boxes in the user form displaying values found on the same row but in other columns (like a vlookup).
I tried this with a drop down list I received from another post on the MrExcel forum but because I plan on adding additional search buttons that link to different spreadsheets the drop down combo box won’t work for me. Plus I didn’t get it right as it kept coding out on me.
I was informed it was best to use an array, but again my end-state is to have multiple search buttons so after reading a bit more it seemed an array would not work. Once I get it right once I’ll just plagiarize it adding the spreadsheet differences, error handling, etc. Any help would truly be appreciated.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Thank you, but this is exactly the site I used the 1st time. However, it provides drop down boxes instead of showing me how to use different spread sheets and search buttons.
 
Upvote 0
Here is my code. I type in the value on the user form in Cbox1.
It continues to come up as "value not found." I also tried Find(VAL(cbox1, but still get nothing.
Sub Mylook()
Dim wsn1 As Range
Set wsn1 = Sheets("uic list").Range("A1:A288").Find(Cbox1, lookat:=xlWhole, LookIn:=xlValues)
If wsn1 Is Nothing Then
MsgBox "Value not found"
Else
'Populate the Myfrm1 with data
TextBox2 = wsn1.Offset(0, 1) 'Down 1 row, over 1 column
TextBox3 = wsn1.Offset(0, 2) 'Down row, over 2 column
'
'
'and 68 more
End If
End Sub

Any Help?
 
Upvote 0
Hi Rick,

To lookup a numeric value on a sheet (Master) and to return the data in that row to a UserForm I use this code, perhaps you can adapt it...

Code:
Private Sub tbLookFor_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
                               ByVal Shift As Integer)
    Dim Product As Range
    Dim x As Long, y As Long
    If KeyCode = 13 And IsNumeric(tbLookFor.Value) = True Then
    
       
    Set Product = Sheets("Master").Range("A1:A300").Find(Val(tbLookFor), lookat:=xlWhole, LookIn:=xlValues)
    If Product Is Nothing Then
        MsgBox "Incorrect Product code, try again"

    Else
        For x = 1 To 97
            If x < 5 Then
                y = x
             Else
                y = x + 1
            End If
            Me.Controls("tbData" & x) = Product.Offset(0, y)
        Next
        
    End If
End If

End Sub

tbLookFor is the name of the text box where I type in the number I am looking for.
tbData is the name of the text boxes where the data from sheet Master is displayed on the UserForm, eg tbData1, tbData2 etc to tbData96

Perhaps your code would be something like this...

Code:
 Private Sub tbLookFor_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
                               ByVal Shift As Integer)
    Dim wsn1As Range
    Dim x As Long, y As Long
    If KeyCode = 13 And IsNumeric(Mylook.Value) = True Then
    
       
    Set wsn1 = Sheets("uic list").Range("A1:A288").Find(Val(Mylook), lookat:=xlWhole, LookIn:=xlValues)
    If wsn1 Is Nothing Then
        MsgBox "Incorrect Product code, try again"

    Else
        For x = 1 To 97
            If x < 5 Then
                y = x
             Else
                y = x + 1
            End If
            Me.Controls("TextBox" & x) = wsn1.Offset(0, y)
        Next

    End If
End If

End Sub

I hope that helps.

Ak
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,237
Messages
6,123,811
Members
449,127
Latest member
Cyko

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top