2014-06-13 54 views
0

我有一个会话,其中我尝试将列表类型验证放到不连续的范围。列表范围来自名称(Range5)的另一张表。范围验证无效过程调用

With Range("storeRanges").Cells.Validation 

Dim ValidationList As Variant 
ValidationList = Sheet2.Range("Range5") 

    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _ 
    Operator:=xlEqual, Formula1:=Join(ValidationList, ",") 

End With 

我上。新增线路“无效的过程调用或参数”。谢谢你的帮助!

+0

仅适用于1D阵列。分配给变体的范围值始终为2D。如果范围是一列,转置它;如果一排,转置两次。 – Rory

+0

是的,在此期间计算出来。解决:'.Add类型:= xlValidateList,AlertStyle:= xlValidAlertStop,_运算符:= xlEqual,Formula1:=“= Range5”' 我把'.Delete'放在'.Add'前面。 – e700k

+0

请不要在标题中写[[已解决]] ......而应将答案作为答案(而非评论)发布,然后接受自己的答案。 –

回答

0

洙,解决方案是:

With Range("storeRanges").Cells.Validation 

Dim ValidationList As Variant 
ValidationList = Sheet2.Range("Range5") 

.Delete 
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _ 
Operator:=xlEqual, Formula1:="=Range5" 

End With 

通知的.DeleteFormula1:="=Range5"