Hello,
I have a data validation list that I want dynamically changed per number of items in a range.
For example, I have my data validation in Range(U15:U21). The values in this range can change to blank values (""). How can I configure my data validation to change to the non-blank items in this list? So if there are 4 non-blank values in U15:U21, the data
validation will change to U15:U18.
Here's my code so far:
'These are the different ranges for the data validation
Const Range1 As String = "=$U$15"
Const Range2 As String = "=$U$15:$U$16"
Const Range3 As String = "=$U$15:$U$17"
Const Range4 As String = "=$U$15:$U$18"
Const Range5 As String = "=$U$15:$U$19"
Const Range6 As String = "=$U$15:$U$20"
Const Range7 As String = "=$U$15:$U$21"
With ThisWorkbook
'Cell U23 shows the # of non-blanks in range U15-U21
Select Case Me.Range("U23").Value
'1 non-blank value, set data validation to 1 list item (U15 only)
Case "1"
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="Range1"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Select
End With
I'm still very new with VBA and can't seem to figure this solution out. The code compiles, but the data validation does not change. Anyone have any advice? Thanks a ton in advance