VBA在变量Range上创建下拉列表

时间:2019-01-07 15:11:59

标签: excel vba drop-down-menu

我现在搜索了很多,但不知道问题出在哪里。其他人也以相同的方式进行操作,并且有效。

这是我的代码,如果有人可以帮助我,那将是非常棒的。预先谢谢你!

该错误发生在“ .Add Type”行中

Sub dropDownMenu()
    Do While (Worksheets("x").Cells(counter + 2, 1) <> "")
        counter = counter + 1
    Loop

    Worksheets("y").Range("D36:D36") = ""
    With Worksheets("y").Range("D36:D36").Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                   xlBetween, Formula1:="=x!A2:A" & 1 + counter & ""
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = "xxx"
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End Sub

0 个答案:

没有答案
相关问题