Create dependent dropdown using Listbox

  • Define The Range on Worksheet -To add ListBox
  • Add The ListBoxes Programatically
  • Create Names
  • Add Values to the Listbox
  • Assign Macro To The ListBox
  • Create Dependent DropDown
  • Delete The ListBoxes
  • Click On below mentioned image to watch video:

    Download The Workbook

     

    Sub Create_Listboxes()
    '==================Create Names=================
    Sheet3.Select
    For C = 1 To 5
    Sheet3.Range(Cells(2, C), Cells(6, C)).Name = Sheet3.Cells(1, C)
    Next
    '==========Craete ListBox1 and assign Macro==========
    Sheet2.Select
    Dim LB1 As ListBox
    With ActiveSheet.Range("B5:C11")
    Set LB1 = ActiveSheet.ListBoxes.Add( _
    Height:=.Height, _
    Top:=.Top, _
    Left:=.Left, _
    Width:=.Width)
    LB1.Name = "Listbox1"
    Dim N As Name
    For Each N In ActiveWorkbook.Names
    LB1.AddItem N.Name
    Next
    LB1.OnAction = "Create_Dependent_DropDown"
    End With
    '==========Craete ListBox2 ==========

    With ActiveSheet.Range("F5:G11")
    Set LB2 = ActiveSheet.ListBoxes.Add( _
    Height:=.Height, _
    Top:=.Top, _
    Left:=.Left, _
    Width:=.Width)
    LB2.Name = "Listbox2"
    End With

    End Sub






    Sub Delete_ListBoxes()

    Dim LB1 As ListBox
    Set LB1 = ActiveSheet.ListBoxes("Listbox1")
    LB1.Delete

    Dim LB2 As ListBox
    Set LB2 = ActiveSheet.ListBoxes("Listbox2")
    LB2.Delete

    End Sub





    Sub Create_Dependent_DropDown()
    Dim LB1 As ListBox
    Set LB1 = ActiveSheet.ListBoxes("Listbox1")
    RangeName = LB1.List(LB1.Value)

    Dim LB2 As ListBox
    Set LB2 = ActiveSheet.ListBoxes("Listbox2")
    LB2.RemoveAllItems
    For i = 1 To Range(RangeName).Rows.Count
    LB2.AddItem Range(RangeName).Rows(i).Value
    Next

    End Sub