Dependent Combobox to Reference Worksheet Range Using Offset

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
Office Version
  1. 365
Platform
  1. Windows
I'm at a loss as to how I can populate particular values in a combobox based on the User's selection in a different combobox. I have 4 comboboxes (cobo_Exec, cobo_Leader, cobo_Mgr, cobo_Assoc). I have a worksheet called Names, where there are 4 columns that correspond to each combobox. What I would like to happen, is if the User selects "Tom G." from cobo_Exec, then only those people that report to Tom G. appear in the cobo_Leader list.

Everything I see on the web is using Select Case with Arrays, but I have too many variables to do this with, and values can change as people move around the organization.

I was trying this code, but I get an error of "Expected function or variable" at the c in red font.

VBA Code:
Private Sub cobo_Leader_Change()

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim m As Workbook
Dim mN As Worksheet
Dim i As Integer
Dim r As Range, c As Range
Dim mNLR As Long

Set m = ThisWorkbook
Set mN = m.Sheets("Names")

mNLR = mN.Range("A" & Rows.Count).End(xlUp).Row

With Me.cobo_Mgr
    Set r = mN.Range("C2:C" & mNLR)
    For Each c In r
        If [COLOR=rgb(184, 49, 47)]c[/COLOR] = Me.cobo_Leader.value Then Me.cobo_Mgr.ListIndex = .AddItem.Offset(, -1)
    Next c
End With
         
Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Upvote 0
@Akuini thank you for replying. Unfortunately, that site is blocked by my work laptop so I'm unable to see the file.

Ok.
There are 3 combobox, i.e combobox1, combobox2, & combobox3 in the Userform.
The code:
VBA Code:
Dim vList
Dim d As Object

'====YOU MAY NEED TO ADJUST THE CODE IN THIS PART:====
'sheet's name where the list  is located.
Private Const sList As String = "Sheet1"
'Table name where the list  is located
Private Const tbl As String = "Table1"


Private Sub UserForm_Initialize()
vList = Sheets(sList).ListObjects("Table1").DataBodyRange.Columns("A:C")
    Set d = CreateObject("scripting.dictionary")
    d.CompareMode = vbTextCompare
End Sub

Private Sub ComboBox1_Change()
       ComboBox2.Value = ""
       ComboBox3.Value = ""

End Sub

Private Sub ComboBox2_Change()
       ComboBox3.Value = ""

End Sub

Private Sub ComboBox1_DropButtonClick()
Dim i As Long
    d.RemoveAll
    For i = LBound(vList) To UBound(vList)
          d(vList(i, 1)) = Empty
    Next
       ComboBox1.List = d.keys
End Sub


Private Sub ComboBox2_DropButtonClick()
Dim i As Long
    d.RemoveAll
    For i = LBound(vList) To UBound(vList)
    If UCase(vList(i, 1)) = UCase(ComboBox1.Value) Then d(vList(i, 2)) = Empty
    Next
       ComboBox2.List = d.keys
End Sub

Private Sub ComboBox3_DropButtonClick()
Dim i As Long
    d.RemoveAll
    For i = LBound(vList) To UBound(vList)
        If UCase(vList(i, 1)) = UCase(ComboBox1.Value) And UCase(vList(i, 2)) = UCase(ComboBox2.Value) Then
            d(vList(i, 3)) = Empty
        End If
    Next
       ComboBox3.List = d.keys
End Sub

Data is in "Table1":
3 combobox, dependent, userform, simple, dictionary, table - 1.xlsm
ABC
1STATECITYREP
2ArizonaMaranaCory
3ArizonaMaranaJayce
4ArizonaTucsonMario
5ArizonaTucsonMark
6ArizonaTucsonPatrick
7ArkansasConwayBode
8ArkansasConwayDrew
9ArkansasConwayQuincy
10ArkansasJonesboroLochlan
11ArkansasJonesboroMakai
12ArkansasJonesboroRuben
13ArkansasSpringdaleTruman
14ArkansasSpringdaleZaiden
15ArkansasSpringdaleZayn
16CaliforniaChula VistaZachariah
17CaliforniaChula VistaZander
18CaliforniaSanta ClaraDominik
Sheet1
 
Upvote 0
VBA Code:
Dim vList
Dim d As Object
'====YOU MAY NEED TO ADJUST THE CODE IN THIS PART:====
'sheet's name where the list  is located.
Private Const sList As String = "Sheet1"
'Table name where the list  is located
Private Const tbl As String = "Table1"

Should this section go in a regular module?
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,148
Members
449,098
Latest member
Doanvanhieu

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