Results 1 to 4 of 4

Cascading Combobox Dropdowns

Threaded View

  1. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Cascading Combobox Dropdowns

    1) To ThisWorkbook module
    Private Sub Workbook_Open()
        Run "sheet2.worksheet_activate"
    End Sub
    Sheet2 module
    Option Explicit
    
    Private dic As Object
    Private x As Variant
    
    Private Sub Worksheet_Activate()
        Dim a, i As Long, w
        Const Combo As String = "Size,Weight,Connection"
        x = Split(Combo, ",")
        Set dic = CreateObject("Scripting.Dictionary")
        dic.CompareMode = 1
        a = Sheets("Connections").Cells(1).CurrentRegion.Value
        For i = 2 To UBound(a, 1)
            If Not dic.exists(CStr(a(i, 1))) Then
                Set dic(CStr(a(i, 1))) = CreateObject("Scripting.Dictionary")
                dic(CStr(a(i, 1))).CompareMode = 1
            End If
            If Not dic(CStr(a(i, 1))).exists(CStr(a(i, 2))) Then
                Set dic(CStr(a(i, 1)))(CStr(a(i, 2))) = CreateObject("Scripting.Dictionary")
                dic(CStr(a(i, 1)))(CStr(a(i, 2))).CompareMode = 1
            End If
            If Not dic(CStr(a(i, 1)))(CStr(a(i, 2))).exists(CStr(a(i, 3))) Then
                ReDim w(1 To 2, 1 To 1)
            Else
                w = dic(CStr(a(i, 1)))(CStr(a(i, 2)))(CStr(a(i, 3)))
                ReDim Preserve w(1 To 2, 1 To UBound(w, 2) + 1)
            End If
            w(1, UBound(w, 2)) = a(i, 4)
            w(2, UBound(w, 2)) = i
            dic(CStr(a(i, 1)))(CStr(a(i, 2)))(CStr(a(i, 3))) = w
        Next
        With Me.ComboBoxConnectionBrand
            .ListFillRange = ""
            .List = dic.keys
        End With
    End Sub
    
    Private Sub ComboBoxConnectionBrand_Change()
        ClearCombo 0
        If Me.ComboBoxConnectionBrand.ListIndex > -1 Then
            Me.OLEObjects("ComboBoxsize").Object.List = dic(Me.ComboBoxConnectionBrand.Value).keys
        End If
    End Sub
    
    Private Sub ComboBoxSize_Change()
        ClearCombo 1
        If Me.ComboBoxSize.ListIndex > -1 Then
            Me.OLEObjects("ComboBoxWeight").Object.List = _
            dic(Me.ComboBoxConnectionBrand.Value)(Me.ComboBoxSize.Value).keys
        End If
    End Sub
    
    Private Sub ComboBoxWeight_Change()
        ClearCombo 2
        If Me.ComboBoxWeight.ListIndex > -1 Then
            Me.OLEObjects("ComboBoxConnection").Object.Column = _
            dic(Me.ComboBoxConnectionBrand.Value)(Me.ComboBoxSize.Value)(Me.ComboBoxWeight.Value)
        End If
    End Sub
    
    Private Sub ClearCombo(s As Long)
        Dim i As Long
        For i = s To UBound(x)
            Me.OLEObjects("Combobox" & x(i)).Object.Clear
        Next
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Cascading Dropdowns - 4 Levels
    By joannakf in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-04-2014, 09:01 AM
  2. [SOLVED] Creating two cascading dropdowns from one variable choice.
    By Emmaly in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-13-2013, 11:27 AM
  3. Multiple cascading dropdowns
    By kokorota in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-21-2013, 09:22 AM
  4. Multiple Cascading Dropdowns
    By Emmaly in forum Excel General
    Replies: 6
    Last Post: 11-03-2011, 07:25 AM
  5. Cascading Dropdowns from table
    By jrjeffcoat64 in forum Excel General
    Replies: 1
    Last Post: 09-06-2011, 02:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1