Apply data validation lists dynamically (vba)
Table of Contents
- Applying data validation lists dynamically using a table
- Applying data validation lists dynamically (vba)
Applying data validation lists dynamically using a table
Create a table
- Select cell range A1:C11
- Go to tab "Insert"
- Click "Table" button
- Select "My table has headers"
- Click OK!
Create a named range
- Go to tab "Formulas"
- Click "Name manager" button
- Click "New..."
- Name: Regiontable
- Refers to:
=OFFSET('Data Validation Lists (table)'!$E$2, 0, 0, COUNTA('Data Validation Lists (table)'!$E:$E)-1)
- Click OK
Apply data validations lists to table
- Select cell A2
- Go to tab "Data"
- Click "Data Validation" button
- Allow:List
- Source:=Regiontable
- Click Ok!
The entire first column is now containing a drop down list in each cell. If the table expands, the new cell has a drop down list!
Download excel *.xlsm file
Apply-data-validation-lists-dynamically2.xlsm
Applying data validation lists dynamically (vba)
The data validation lists contain values from named range. The named range (E2:E8) expands when you add new values to the list. The animated gif shows you that.
The animated gif below also shows you when adding a new company name in cell B11, a drop down list (Data validation list) is instantly applied to cell range A2:A11. The vba code in this sheet and a named formula make it all happen!
Let me explain how I created this sheet
Dynamic named range
- Go to "Formulas" tab
- Click "Name Manager" button
- Click "New.."
- Type Region
- Type in source field:=OFFSET('Data Validation Lists'!$E$2, 0, 0, COUNTA('Data Validation Lists'!$E:$E)-1)
- Click Close
Add vba code to sheet
VBA code
Private Sub Worksheet_Change(ByVal Target As Range)
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Lrow As Single
Dim AStr As String
Dim Value As Variant
If Not Intersect(Target, Range("$B:$C")) Is Nothing _
Or Not Intersect(Target, Range("E:E")) Is Nothing Then
Lrow = ActiveSheet.Range("B" & Rows.Count).End(xlUp).Row
For Each Value In Range("Region")
AStr = AStr & "," & Value
Next Value
With ActiveSheet.Range("A2:A" & Lrow).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=AStr
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End If
End Sub
Download excel *.xlsm file
Apply data validation lists dynamically.xlsm
Related posts:
Dependent data validation lists in multiple rows
How to use a table name in data validation lists and conditional formatting formulas
Add values to a data validation list (vba)
Lookup between two lists of data to highlight missing data using conditional formatting in excel
Search for multiple text strings in multiple cells and use in data validation in excel























I read through your blog and I do have question.
Why not just use the built-in table functionality and have Excel do the VBA portion automatically?