Populate UserForm Label boxes based on ComboBox text string match

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,604
Office Version
  1. 365
Platform
  1. Windows
Hey all

I'm using a range found in Stock sheet range B3:B10 to populate ComboBox1 in my userform.
When the user selects a text string from ComboBox1 I would like a VLookup (or similar) to look for an exact match to this selected ComboBox value through the range B3:B10 in Stock sheet.
Once found then populate Label1 of the userform with the value found in corresponding column D and Label2 with the value found in corresponding column E

UserForm is named Stock

Hope this makes sense and thanks in advance
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Something like this:
VBA Code:
Private Sub ComboBox1_Change()

    If ComboBox1.ListIndex > -1 Then
    Dim c As Range
        With Sheets("Stock")
            Set c = .Range("B3:B10").Find(What:=ComboBox1.Text, LookIn:=xlValues, lookAt:=xlWhole, _
            SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
                If Not c Is Nothing Then
                    Me.Label1 = .Cells(c.Row, "D")
                    Me.Label2 = .Cells(c.Row, "E")
                End If
        End With
    
    End If

End Sub
 
Upvote 1
Something like this:
VBA Code:
Private Sub ComboBox1_Change()

    If ComboBox1.ListIndex > -1 Then
    Dim c As Range
        With Sheets("Stock")
            Set c = .Range("B3:B10").Find(What:=ComboBox1.Text, LookIn:=xlValues, lookAt:=xlWhole, _
            SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
                If Not c Is Nothing Then
                    Me.Label1 = .Cells(c.Row, "D")
                    Me.Label2 = .Cells(c.Row, "E")
                End If
        End With
   
    End If

End Sub
Perfect - thanks a lot
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,223,157
Messages
6,170,418
Members
452,325
Latest member
BlahQz

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