我为范围制作了全局字符串常量。
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
OR
With wkDataToUse
.Range([{Graph_Cl, Graph_Vl, Graph_VlS}]).ClearContents
End With
如何清除一行代码中的所有范围?
答案 0 :(得分: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