通过VBA在数据验证中使用间接功能

时间:2015-07-16 13:37:48

标签: excel vba excel-vba

我通过VBA使用excel表中的间接功能,当我尝试替换单元格地址时出现错误。

=indirect(F5)

我无法用变量替换“F5”这里是我的代码。

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

1 个答案:

答案 0 :(得分:1)

使用范围

With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="=INDIRECT(""" & Range("F5").Address(False, False) & """)"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With