I have an array of values. I want to show those values in Excel Cell as drop down list using VBA.
Here is my code. It shows "Type Mismatch Error!"
Dim xlValidateList(6) As Integer
xlValidateList(1) = 1
xlValidateList(2) = 2
xlValidateList(3) = 3
xlValidateList(4) = 4
xlValidateList(5) = 5
xlValidateList(6) = 6
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
The problem occurs in following line...
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
Please let me where the problem is... Thanks in advance
based on examples above and examples found on other sites, I created a generic procedure and some examples.
The accepted answer is correct but needs to be wary that this way imposes a 255 character limit. Better to reference an actual worksheet range object.
This worked on my test file (note the index in VBA starts from zero):
I used
xlEqual
because that's what I think you are trying to get people to select one of the list.You are defining your array as
xlValidateList()
, so when you try to assign the type, it gets confused as to what you are trying to assign to the type.Instead, try this: