Excel VBA将验证列表读入变量

时间:2013-09-19 11:31:11

标签: excel vba

我试图找到一个将验证列表读入变量的Excel VBA代码。

我正在使用Excel 2010版本。

在下面的代码中,我使用变量qNR动态设置值,并显示在下拉菜单中。稍后我需要读取验证列表中的值,删除或更新某些值并设置新值。

我找不到任何将验证列表读入变量的示例代码。

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

End With

谢谢!

1 个答案:

答案 0 :(得分:2)

假设它是一个列表类型(validation type 3),那么Debug.Print Range(yourRange).Validation.Formula1应该打印出一个列表。所以Object.Validation.Formula1似乎适合你。有关详细信息,请参阅here