How to pass values from an array to a drop down list in a certain cell (not combo list) in excel VBA

后端 未结 2 748
轮回少年
轮回少年 2021-01-23 03:19

I\'m trying to pass values from an array to a drop down list in a specifc cell. Say I have an array which contains the values 1,2,3 and I want cell A1 to contain a drop down lis

2条回答
  •  我在风中等你
    2021-01-23 03:49

    This should give you a way of doing it:

    Dim myArray
    myArray = Array("1", "2", "3")
    
    Range("A" & 1).Select
    
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:=myArray(0) & "," & myArray(1) & "," & myArray(2)
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    

提交回复
热议问题