gpt4 book ai didi

vba - 使用一行代码清除范围数组

转载 作者:行者123 更新时间:2023-12-03 02:11:45 27 4
gpt4 key购买 nike

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

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

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

最佳答案

要传递多个范围地址,您需要逗号分隔的字符串格式:"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

关于vba - 使用一行代码清除范围数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10563423/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com