首页 > 解决方案 > vba在变量范围上创建下拉列表

问题描述

我现在搜索了很多,我不知道问题出在哪里。其他人也这样做了,而且效果很好。

这是我的代码,如果有人可以帮助我,那就太棒了。先感谢您!

错误发生在“.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

标签: excelvbadrop-down-menu

解决方案


推荐阅读