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
Use the Add method of the DataValidation property of the Range object. Use the AlertStyle parameter to specify the style of the alert warning dialog. Use the Operator parameter together with the Formula parameters to specify a rule.
Create drop down lists in a UserForm, by using the ComboBox control. In this example, there are two ComboBox controls, one for Part ID, and one for Location.
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:
Dim MyList(5) As String
MyList(0) = 1
MyList(1) = 2
MyList(2) = 3
MyList(3) = 4
MyList(4) = 5
MyList(5) = 6
With Range("A1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=Join(MyList, ",")
End With
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With