Results 1 to 4 of 4

dynamically populate dropdown lists

Threaded View

  1. #3
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: dynamically populate dropdown lists

    Try this:-
    The way you have named you sheets can lead to some confusion so I have changed a few thing:-
    Your Basic Sheet is Called:- Data
    The Five other sheets are named :- Sht1,Sht2,Sht3,Sht4 and Sht5.
    The validation cell Headers have changed slightly, you will see. NB:- You require to keep the "_" in the header string
    Everything else remains the same.
    Nb:- When you Insert a number in columns "A" of shet "Data" and the Validation list arrives in column "E" and you select a sheet name, then the code will select that sheet, although you don't explicitly state that requirement.

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Rng As Range, Dn As Range
    Dim n As Integer
    Dim Dic As Object
    Dim Str As String
    Str = vbNullString
    
    
    If Not Target = vbNullString Then
        If Target.Column = 1 Then
            Set Dic = CreateObject("scripting.dictionary")
                Dic.CompareMode = vbTextCompare
    For n = 1 To 5
        With Sheets("Sht" & n)
            Set Rng = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
                For Each Dn In Rng
                    If Not Dic.exists(Dn.Value) Then
                        Dic.Add Dn.Value, Dn.Parent.Name
                    Else
                        Dic.Item(Dn.Value) = Dic.Item(Dn.Value) & "," & Dn.Parent.Name
                    End If
                Next Dn
        End With
    Next n
    
    Str = Dic.Item(Target.Value)
    Select Case UBound(Split(Str, ","))
        Case -1: Str = "None_Available"
        Case 0: Str = "Only_one_Option" & "," & Str
        Case Is > 0: Str = "Pick_Your_Sheet" & "," & Str
    End Select
    
    With Target.Offset(, 4)
        .Validation.Delete
        .Validation.Add Type:=xlValidateList, Formula1:=Str
        .Value = Split(Str, ",")(0)
    End With
    
    ElseIf Target.Column = 5 And Target.Count = 1 Then
       If InStr(Target, "_") = 0 Then
       Sheets(Target.Value).Select
        End If
    End If
    End If
    End Sub
    Regards Mick
    Last edited by MickG; 10-24-2013 at 08:56 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. how to ignore blank cells in creatig dropdown lists (validation lists)
    By Elainefish in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-02-2013, 07:45 AM
  2. Replies: 3
    Last Post: 02-20-2013, 12:54 AM
  3. [SOLVED] Cascading dropdown lists all tied to first dropdown
    By ruthl in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-18-2012, 08:03 PM
  4. using dropdown lists to populate range of cells
    By tsiguy96 in forum Excel General
    Replies: 11
    Last Post: 03-16-2012, 05:58 PM
  5. Replies: 21
    Last Post: 12-02-2009, 03:27 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