可变范围上的VBA Excel验证列表

时间:2016-12-23 19:30:22

标签: excel vba list validation

我尝试使用此代码在Excel中设置验证列表。我试图用变量替换特定的细胞,但我不能用固定的细胞来解决它。

谢谢。

With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="=Range(Cells(5, 15), Cells(6, 15))"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With

1 个答案:

答案 0 :(得分:2)

试试这个:

    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:= "=" & Range(Cells(5, 15), Cells(6, 15)).Address

或者这个:

   .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:= "=$O$5:$O$6"