I want to add "data validation" including a drop down menu to some cells in a Workbook that uses numeric columns. I only managed to do it with alphabetical columns.
When I execute the following code I get the error message "1004" and the macro stops at the line with the Formula1 (excel settings to numerical columns):
Sub foo_numeric()
Dim rngTest As Range 'Range where the Data validation should be applied
Dim wsTest As Worksheet
Set wsTest = Worksheets("WorkSheetName")
Set rngTest = wsTest.Range(wsTest.Cells(1, 2), wsTest.Cells(5, 2))
With rngTest.Validation
.Delete
.Add Type:=xlValidateList, _
Formula1:="=WorkSheetName!Z1S1:Z22S1"
End With
End Sub
When I switch the settings to alphabetical columns and execute the following code, I get no error message and the macro works smoothly:
Sub foo_alphabetical()
Dim rngTest As Range 'Range where the Data validation should be applied
Dim wsTest As Worksheet
Set wsTest = Worksheets("WorkSheetName")
Set rngTest = wsTest.Range("B1:B5")
With rngTest.Validation
.Delete
.Add Type:=xlValidateList, _
Formula1:="=WorkSheetName!$A$1:$A$22"
End With
End Sub
Is there some error in my code that I missed? How can I use data validation with numerical columns?
Remark: To put a String with the possible options into Formula1 is not an option as the string would be too big.