3x dependent drop-downs

JohnBi

New Member
Joined
Aug 1, 2016
Messages
31
Office Version
  1. 2019
Platform
  1. Windows
Good day to everyone.
I am not able to set up properly the 3x dependent drop-downs.:
Column B = first dropdown; then Column I for the second drop-dow and Column Q for the third
Only column B it is Ok. Then the 2nd and 3th dropdown not at all!
Could you please help to find out where am I wrong please?
Here is the code as result of researchs, copy and a little bit of luck ...!


Option Explicit
Private Sub ComboBox1_Change()
Dim sh As Worksheet
Dim r As Long
Dim m As Long
FillList
Me.ComboBox2.Clear
Set sh = Worksheets("New")
m = sh.Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For r = 2 To m
If sh.Range("B" & r) = Me.ComboBox1.Value Then
If Application.WorksheetFunction.CountIf(sh.Range("I2:I" & r), sh.Range("I" & r)) = 1 Then
Me.ComboBox2.AddItem sh.Range("I" & r).Value
End If
End If
Next r
End Sub

Private Sub ComboBox2_Change()
Dim sh As Worksheet
Dim r As Long
Dim m As Long
FillList
Me.ComboBox3.Clear
Set sh = Worksheets("New")
m = sh.Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For r = 2 To m
If sh.Range("I" & r) = Me.ComboBox2.Value Then
If Application.WorksheetFunction.CountIf(sh.Range("Q2:Q" & r), sh.Range("Q" & r)) = 1 Then
Me.ComboBox3.AddItem sh.Range("Q" & r).Value
End If
End If
Next r
End Sub

Private Sub ComboBox3_Change()
FillList
End Sub

Private Sub CommandButton1_Click()
Unload Me
End Sub

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim sh As Worksheet
Dim r As Long
Dim c As Long
Load UserForm1
Set sh = Sheets("New")
r = Me.ListBox1
For c = 1 To 10
UserForm1.Controls("TextBox" & c).Value = sh.Cells(r, c).Value
Next c
UserForm1.Show
FillList
End Sub

Private Sub UserForm_Initialize()
Dim sh As Worksheet
Dim r As Long
Dim m As Long
Set sh = Sheets("New")
m = sh.Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For r = 2 To m
If Application.WorksheetFunction.CountIf(sh.Range("B2:B" & r), sh.Range("B" & r)) = 1 Then
Me.ComboBox1.AddItem sh.Range("B" & r).Value
End If
Next r
FillList
End Sub

Private Sub FillList()
Dim sh As Worksheet
Dim r As Long
Dim c As Long
Dim m As Long
Dim arr()
Dim n As Long
Dim f As Boolean
Set sh = Worksheets("New")
m = sh.Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For r = 2 To m
f = (sh.Range("B" & r).Value = Me.ComboBox1.Value) Or (Me.ComboBox1.ListIndex = -1)
If f Then
f = (sh.Range("I" & r).Value = Me.ComboBox2.Value) Or (Me.ComboBox2.ListIndex = -1)
If f Then
f = (sh.Range("Q" & r).Value = Me.ComboBox3.Value) Or (Me.ComboBox3.ListIndex = -1)
End If
End If
If f Then
n = n + 1
ReDim Preserve arr(1 To 19, 1 To n)
' Store the row number in the first (hidden) column
arr(1, n) = r
For c = 2 To 18
arr(c + 1, n) = sh.Cells(r, c).Value
Next c
End If
Next r

With ListBox1
'.ColumnHeads = True
.ColumnWidths = "20;20;100;50;0;0;0;0;0;60;0;0;0;50;0;00;50;50"
.ListStyle = fmListStylePlain
End With

If n > 0 Then
Me.ListBox1.Column = arr
Else
Me.ListBox1.Clear
End If
End Sub



Thanks in advance. John
 

Attachments

  • New_2.gif
    New_2.gif
    78 KB · Views: 13
  • New_1.gif
    New_1.gif
    204.3 KB · Views: 13

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,223,879
Messages
6,175,150
Members
452,615
Latest member
bogeys2birdies

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