Programmatically creating validation list
Place the data in some text file delimiting it with comma eg(a,b,c).
Read that data using VBA into a string variable eg ValidationList.
Use some thing like this
With Range("A1").Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=ValidationList
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Alistair Collins
Wet Gas Metering Specialist at Solartron ISA, as well as currently taking a Flow Measurement and Fluid Mechanics EngD, with a little bit of time for playing in Go and other programming languages... ..although with a wife, two kids, playing keyboards at church etc, it's a fun and busy life!!
Updated on June 04, 2022Comments
-
Alistair Collins almost 2 years
I have an array of data that is coming in to the VBA code from an external source. I want to be able to assign that data to use as a validation in a dropdown box in a cell in one of the sheets in this workbook. However, I do not want to copy that data into a sheet and then use a named range - there may be quite a lot of data, and that would not feel very efficient!
I'm sure there must be a way - but I haven't found one yet. Any ideas?