我有多个变量要与“with”语句一起使用,而不是多个变量。有没有办法做到这一点?我有下面的片段,并想使用变量 a、b、c、d、e 和 f
With a
.AutoFilter 1, "0"
With a
.clearContents
.ClearComments
End With
End With
最佳答案
而不是 a
, b
, c
, d
, e
和 f
定义一个数组并循环
Dim Vars(5) As Variant 'choose your type instead of Variant
'fill your variables with content
Vars(0) = a
Vars(1) = b
' …
Dim Var As Variant 'keep this Variant
For Each Var in Vars
With Var
.AutoFilter 1, "0"
With Var
.clearContents
.ClearComments
End With
End With
Next Var
关于excel - VBA "With"语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71799608/