2

我已经为范围创建了全局字符串常量。

Global Const Graph_Cl As String = "G2:G13"
Global Const Graph_Vl As String = "I2:I13"
Global Const Graph_VlS As String = "L2:L13"

我想使用一行代码清除这些范围。

With wkDataToUse
    .Range(Graph_Cl, Graph_Vl, Graph_VlS).ClearContents
End With

但我得到错误:

"Wrong no of arguments or invalid property assignment!"

我什至试过这个:

With wkDataToUse
    .Range(Array(Graph_Cl, Graph_Vl, Graph_VlS)).ClearContents
End With

或者

With wkDataToUse
    .Range([{Graph_Cl, Graph_Vl, Graph_VlS}]).ClearContents
End With

如何清除一行代码中的所有范围?

4

1 回答 1

4

要传递多个范围地址,您需要逗号分隔的字符串格式:"a:b,c:d,e:f"所以你可以;

.Range(Graph_Cl & "," & Graph_Vl & "," & Graph_VlS).ClearContents

你也可以;

Union(.Range(Graph_Cl), .Range(Graph_Vl), .Range(Graph_VlS)).ClearContents
于 2012-05-12T12:00:08.033 回答