Userform multiple vlookup based on combobox

trev1234

New Member
Joined
Mar 13, 2021
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have a userform with combobox6 on it which has two options Full and Part based on what is selected I want to update a textbox using vlookup the issue I am having is that the vlookup range is different dependent on the selection from the combobox, I have tried the below but I cannot get it to work. any help would be appreciated.

Combobox3 if the vlookup value this is also on the userform

VBA Code:
Private Sub ComboBox6_Change()


If ComboBox6 = "Full" Then
TextBox2.Value = Application.VLookup(Me.ComboBox3.Value, Sheets("Absence Totals").Range("a:g"), 7, 0)
ElseIf ComboBox6 = "part" Then
TextBox2.Value = Application.VLookup(Me.ComboBox3.Value, Sheets("Absence Totals").Range("a:h"), 8, 0)


Else
End If


End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try this And comment what message appears.

VBA Code:
Private Sub ComboBox6_Change()
  Dim r As Range, f As Range
  
  TextBox2.Value = ""
  
  If comboBox3.Value = "" Then
    MsgBox "Fill combo3"
    Exit Sub
  End If
  
  Set r = Sheets("Absence Totals").Range("A:A")
  Set f = r.Find(comboBox3.Value, , xlValues, xlWhole, , , False)
  If Not f Is Nothing Then
    If LCase(ComboBox6.Value) = LCase("Full") Then
      TextBox2.Value = f.Offset(0, 6)
    ElseIf LCase(ComboBox6.Value) = LCase("Part") Then
      TextBox2.Value = f.Offset(0, 7)
    End If
  Else
    MsgBox "Data does not exist"
  End If
End Sub
 
Upvote 0
Solution
Try this And comment what message appears.

VBA Code:
Private Sub ComboBox6_Change()
  Dim r As Range, f As Range
 
  TextBox2.Value = ""
 
  If comboBox3.Value = "" Then
    MsgBox "Fill combo3"
    Exit Sub
  End If
 
  Set r = Sheets("Absence Totals").Range("A:A")
  Set f = r.Find(comboBox3.Value, , xlValues, xlWhole, , , False)
  If Not f Is Nothing Then
    If LCase(ComboBox6.Value) = LCase("Full") Then
      TextBox2.Value = f.Offset(0, 6)
    ElseIf LCase(ComboBox6.Value) = LCase("Part") Then
      TextBox2.Value = f.Offset(0, 7)
    End If
  Else
    MsgBox "Data does not exist"
  End If
End Sub
That is exactly what I am looking for, thank you DanteAmor. Once again someone in this forum has saved me hours of headaches :)
 
Upvote 0
Im glad to help you, thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,519
Members
448,968
Latest member
Ajax40

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