Dynamic dropdown list for large number of items

BJQQQ

New Member
Joined
Aug 26, 2015
Messages
3
Hello
I would like to generate a dynamic dropdown list (with "Strength" subject to the selection of "product name". I used the method described in How to quickly create dynamic drop down list in Excel?.

However, as shown in the Table, there are many products with spaces and commas, making the cell naming process complicated. Besides, most of the items only have one option and the list is very long to name cell one by one.

What is the easiest way of dealing with this?

Thank you!

Sample data
Product nameStrengthForm
Aciclovir200 mgTAB-CAP
Amlodipine5 mgTAB-CAP
Amitriptyline25 mgTAB-CAP
Amoxicillin250 mgTAB-CAP
Amoxicillin500 mgTAB-CAP
Amoxicillin250 mg/5 mlSUSPEN
Artemether+Lumefantrine20 mg+120 mgTAB-CAP
Acetylsalicylic Acid100 mgTAB-CAP
Atenolol50 mgTAB-CAP
Penicillin, Benzathine Benzyl2.4M IUPOWDER
Beclometasone100 mcg/doseINHALER
Captopril25 mgTAB-CAP
Carbamazepine200 mgTAB-CAP
Ceftriaxone1 gVIAL
Ciprofloxacin500 mgTAB-CAP

<tbody>
</tbody>
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
How many drop down do you want , one for each column ??? ,or something else.
Please show/describe what you want and an example of the results you expect to see for a specific selection
 
Upvote 0
How many drop down do you want , one for each column ??? ,or something else.
Please show/describe what you want and an example of the results you expect to see for a specific selection


Thanks for following this up.
I would like three dropdown lists, as shown. For example, when selecting Amoxicillin in B1, I would like: Cell B2 to have a dropdown list for 250mg, 500mg and 250mg/5mL. Cell B3 will be based on selection in cell B2. Based on How to quickly create dynamic drop down list in Excel?., I could name cell range for amoxicillin and link data validation to the name. But I have a large number of products and some products have spaces and commas, making the naming process cumbersome.

thanks for helping and I hope this is clear.

Column A
PRODUCT NAME

Column B
Amoxicillin
STRENGTH500 mg
FORMTAB-CAP


<colgroup><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Since the data in one column relies on the other column this can get complicated, but definitely doable. Try looking at this video by Mike Girven from excel is fun. He does a thorough job explaining this concept and it seems to line up with what you need. It's a little long. He has accompanying worksheets somewhere on the site. I have used this in creating my own dynamic lists. It's good to keep this video for reference even if you don't use it now.

https://www.youtube.com/watch?v=5ko5ES8ZLuY&list=PLrRPvpgDmw0kjL4875H36yNhWBb0f-nci&index=15
 
Upvote 0
1) Place your Data in sheet1 columns "A to C"
2) Copy code below.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim Rng         As Range
Dim Dn          As Range
Dim Dic         As Object
If Target.Address(0, 0) = "B1" Then
    With Sheets("Sheet1") 'Change this to sheet with data
    Set Rng = .Range(.Range("A1"), .Range("A" & Rows.Count).End(xlUp))
      End With
        Set Dic = CreateObject("scripting.dictionary")
            Dic.CompareMode = vbTextCompare
For Each Dn In Rng: Dic(Dn.Value) = Empty: Next
With Range("B1").Validation
    .Delete
    .Add Type:=xlValidateList, Formula1:=Join(Dic.keys, ",")
End With
End If
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
Dim Dn              As Range
Dim Rng             As Range
Dim Dic             As Object
Dim n               As Integer
Dim rS              As Integer
Dim jRw             As String
Dim jTg             As String
If Not Intersect(Target, Range("B1:B2")) Is Nothing Then
  Application.EnableEvents = False
   For n = 1 To 3 - Target.Row
        Target.Offset(n).Validation.Delete
        Target.Offset(n).Value = ""
   Next n
Application.EnableEvents = True
With Sheets("Sheet1")
Set Rng = .Range(.Cells(2, Target.Row), .Cells(Rows.Count, Target.Row).End(xlUp))
End With
  Set Dic = CreateObject("Scripting.Dictionary")
    Dic.CompareMode = 1
   If Not Rng(1).Offset(1) = "" Then
   For Each Dn In Rng
       rS = Target.Row - 1
       If rS > 0 Then
       jRw = Join(Application.Transpose(Application.Transpose(Dn.Offset(, -rS).Resize(, rS + 1))))
       jTg = Join(Application.Transpose(Target.Offset(-rS).Resize(rS + 1)))
        Else
       jRw = Dn.Value: jTg = Target.Value
       End If
      
        If jRw = jTg Then
         If Not Dic.exists(Dn.Offset(, 1).Value) Then
                 Dic(Dn.Offset(, 1).Value) = Empty
            End If
        End If
      Next Dn
   
If Dic.Count > 0 Then
 With Target.Offset(1).Validation
    .Delete
    .Add Type:=xlValidateList, Formula1:=Join(Dic.keys, ",")
End With
End If
End If
End If
End Sub

Open sheet 2 and Right click sheet tab.
From dropdown Select "View Code" , vbwindow appears.
Paste code into vbwindow.
Close Vbwindow

Double click in cell "B1", Validation drop down appears in "B1"
Select value from drop down, Validation appears in "B2"
Select value from "B2", Validation appears in "B3"

Change selection as Required
NB:- This code will not work on a "Mac"
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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