gpt4 book ai didi

vba - Excel VBA : Consolidate the iterating group in "For Each" block

转载 作者:行者123 更新时间:2023-12-03 01:54:18 26 4
gpt4 key购买 nike

我发现对于我的示例来说,两个数组的串联/追加是一个过于繁琐的过程。但是如何在单个 block 中使用 For Each 迭代两个工作表数组(如何缩短以下代码)?

arr1 = Array("Sheet2", "Sheet3")
arr2 = Array("Sheet5", "Sheet6")

For Each sh In Sheets(arr1)
sh.Visible = True
Next sh

For Each sh In Sheets(arr2)
sh.Visible = True
Next sh

最佳答案

您始终可以将小型数组组合 super 数组。例如:

Sub Klai()
arr1 = Array("Sheet2", "Sheet3")
arr2 = Array("Sheet5", "Sheet6")

arr3 = Array(arr1, arr2)

For Each a In arr3
For Each b In a
MsgBox Sheets(b).Name
Sheets(b).Visible = True
Next b
Next a
End Sub

关于vba - Excel VBA : Consolidate the iterating group in "For Each" block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38420965/

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