Update label of Userform doing Vlookup from comboboxes

Joined
Nov 5, 2019
Messages
9
Hi,

I'm trying to get a userform label to update after selecting a bunch of comboboxes to give me a file name.
The file name is made up of acronyms that the vlookup is searching for e.g. General = GEN so when I click General in my dropdown combobox, that portion of the filename is entered in Label 8 and so on.

The problem is that I need to click on the label to show the resulting file name. How can I update this automatically? I have tried Me.Repaint & DoEvents to no avail.


VBA Code:
Private Sub Label8_Click()

If Me.ComboBox1 = "" Or Me.ComboBox2 = "" Or Me.ComboBox3 = "" Or Me.ComboBox4 = "" Or Me.ComboBox5 = "" Or Me.ComboBox6 = "" Then Exit Sub

Label8.Caption = Application.WorksheetFunction.VLookup(Me.ComboBox1, Sheet3.Range("A2:B3"), 2, 0) & "-" & Application.WorksheetFunction.VLookup(Me.ComboBox2, Sheet4.Range("A2:B83"), 2, 0) & "-" & Application.WorksheetFunction.VLookup(Me.ComboBox3, Sheet2.Range("A2:B9"), 2, 0) & "-" & Application.WorksheetFunction.VLookup(Me.ComboBox4, Sheet5.Range("A2:B131"), 2, 0) & "-" & Application.WorksheetFunction.VLookup(Me.ComboBox5, Sheet6.Range("A2:B70"), 2, 0) & Formatted_Num

End Sub

I also had this but it does the same thing

VBA Code:
Private Sub Label8_Click()

If Me.ComboBox1 = "" Or Me.ComboBox2 = "" Or Me.ComboBox3 = "" Or Me.ComboBox4 = "" Or Me.ComboBox5 = "" Or Me.ComboBox6 = "" Then Exit Sub
With Me

.Label8 = Application.WorksheetFunction.VLookup(Me.ComboBox1, Sheet3.Range("A2:B3"), 2, 0) & "-" & Application.WorksheetFunction.VLookup(Me.ComboBox2, Sheet4.Range("A2:B83"), 2, 0) & "-" & Application.WorksheetFunction.VLookup(Me.ComboBox3, Sheet2.Range("A2:B9"), 2, 0) & "-" & Application.WorksheetFunction.VLookup(Me.ComboBox4, Sheet5.Range("A2:B131"), 2, 0) & "-" & Application.WorksheetFunction.VLookup(Me.ComboBox5, Sheet6.Range("A2:B70"), 2, 0) & Formatted_Num

End With

End Sub
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,473
Office Version
  1. 2019
Platform
  1. Windows
Hi,
one way would be to make the code a common code & call it from your comboboxes change events

Untested by try placing following codes in your userform & see if does what you want

VBA Code:
Private Sub ComboBox1_Change()
    GetFileName
End Sub
Private Sub ComboBox2_Change()
    GetFileName
End Sub

Private Sub ComboBox3_Change()
    GetFileName
End Sub
Private Sub ComboBox4_Change()
    GetFileName
End Sub
Private Sub ComboBox5_Change()
    GetFileName
End Sub

Private Sub GetFileName()
    Dim i As Integer
    
    Me.Label8.Caption = ""
    For i = 1 To 6
        If Len(Me.Controls("ComboBox" & i).Value) = 0 Then Exit Sub
    Next i
    
    With Application.WorksheetFunction
        Label8.Caption = .VLookup(Me.ComboBox1, Sheet3.Range("A2:B3"), 2, 0) & "-" & _
                        .VLookup(Me.ComboBox2, Sheet4.Range("A2:B83"), 2, 0) & "-" & _
                        .VLookup(Me.ComboBox3, Sheet2.Range("A2:B9"), 2, 0) & "-" & _
                        .VLookup(Me.ComboBox4, Sheet5.Range("A2:B131"), 2, 0) & "-" & _
                        .VLookup(Me.ComboBox5, Sheet6.Range("A2:B70"), 2, 0) & Formatted_Num
    End With

End Sub

Dave
 

Watch MrExcel Video

Forum statistics

Threads
1,126,989
Messages
5,622,020
Members
415,874
Latest member
JockPC

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
Top