I'm trying to add a data validation pulldown list, and I've been debugging it for a while to no avail. I'm getting a Run-time error 1004, Application-defined or object defined error. The error occurs in Formula1 setting part of the Validation.Add statement.
I've tried using a string reference to a named range, a string reference to a standard range, and, as shown below, a comma delimited list string generated from the list on the worksheet as shown in the code below. I have checked the list string with Debug.Print and got the expected result.
Sub addPT_Validation()
Dim sValidationList As String
Dim cell As Range
For Each cell In ThisWorkbook.Names("PT_Puldown").RefersToRange
sValidationList = sValidationList & cell.Value & ","
Next cell
sValidationList = Left(sValidationList, Len(sValidationList) - 1)
With ActiveSheet.Range("D14").Validation
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlEqual, _
Formula1:=sValidationList
.IgnoreBlank = True
.InCellDropdown = True
.ShowError = True
End With
End Sub
Thanks in advance for any guidance.