对于每个功能,循环使用特定的工作表 [英] For Each Function, to loop through specifically named worksheets

查看:157
本文介绍了对于每个功能,循环使用特定的工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出正确的方法来编写一个通过特定名称(Jan,Feb,...,Dec)的12个工作表的宏。我认为也许每个功能将是一个不错的选择,所以我尝试以下:

  dim crntSht作为工作表
设置crntsht =(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov )
每个crntsht在工作表



结束

这显然没有工作,因为我以错误的方式定义了crntsht。 / p>

任何人都可以建议最好的方法来循环遍历所有12张一张,一次,并跳过同一工作簿中的所有其他工作表。



谢谢

解决方案

啊,Tim打败了我...我的答案略有不同,但是...

  Sub LoopThroughSheets()

Dim Months As Variant
Dim Month As Variant

Months = Array(Jan,Feb,Mar,Apr,May,Jun,Jul,_
Aug,Sep ,11月,十二月)

每个月的月份
'代码到这里。
下个月

End Sub


Im trying to figure out the right way to code a macro that goes through 12 worksheets with specific names (Jan,Feb,...,Dec). I thought maybe for each function will be a good choice so i tried the following:

dim crntSht as worksheet
set crntsht=("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
for each crntsht in worksheets
.
.
.
end for

this obviously did not work since I defined crntsht in the wrong manner.

Can anyone suggest the best way to loop through all 12 sheets once each, and skip all other sheets in the same workbook?

Thanks

解决方案

Ah, Tim beat me... my answer is slightly different however...

Sub LoopThroughSheets()

    Dim Months As Variant
    Dim Month As Variant

    Months = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", _
         "Aug", "Sep", "Oct", "Nov", "Dec")

    For Each Month In Months
        'Code goes here.
    Next Month

End Sub

这篇关于对于每个功能,循环使用特定的工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆