阅读背景:

VBA excel代码:无法在验证中为formula1指定命名范围

来源:互联网 

How can i add a validation list by vba code that will refer to a named range? So that the list will contain the values of a named range? I can do this like Formula1:="=$A

How can i add a validation list by vba code that will refer to a named range? So that the list will contain the values of a named range? I can do this like Formula1:="=$A$1:$A$10" but how can i give a named range?

如何通过vba代码添加验证列表,该代码将引用命名范围?这样列表将包含命名范围的值?我可以像Formula1:=“= $ A $ 1:$ A $ 10”这样做,但我怎样才能给出一个命名范围?

1 个解决方案

#1


13  

You can use the following code:

您可以使用以下代码:

'Create the named range (if not done already)
ActiveWorkbook.Names.Add Name:="listdata", RefersTo:= "=Sheet2!$A$1:$A$10" 
'Set a validation list on the cells that will refer to the named range
With Range("A1:A100") 
    With .Validation 
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ 
        xlBetween, Formula1:="=listdata" 
    End With 
End With

:$A" but how can i give a named range?How can i add a validation list by vba code tha




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: