gpt4 book ai didi

vba - 嵌套的 For 循环 'with...end with'

转载 作者:行者123 更新时间:2023-12-02 18:58:28 25 4
gpt4 key购买 nike

所以我尝试使用 -with...end with-在 -for..next- 循环内。我们的想法是把所有这些东西都写在每张纸上。下面的代码是伪代码

    For Sheet = Sheet1 to Sheet10
With Sheet
...code
End With
Next

所以我有 10 张。工作表 1、工作表 2、工作表 3 等我似乎不明白如何循环所有这些工作表

最佳答案

你应该尝试这个答案

https://stackoverflow.com/a/21918281/1214743

Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
ResizeColumns WS
Next WS

如果您不想选择工作簿中的每个工作表,您可以创建一个工作表名称数组,然后对它们进行 foreach。

关于vba - 嵌套的 For 循环 'with...end with',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31748086/

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