엑셀 VBA #25 / For Each~Next_1 [VBA] - 시트숨기기

엑셀 VBA #25 / For Each~Next_1 [VBA] - 시트숨기기

For Each~Next문으로 시트 숨기기

Sub For_Each_Next로_시트_숨기기1()

Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
      If sh.Name = "메인" Then
      ElseIf sh.Name = "외우기" Then
      Else
            sh.Visible = False
      End If
Next

End Sub

 

 

For Each~Next문 & 동적배열로 시트 숨기기

Sub For_Each_Next_and_동적배열로_시트_숨기기()

Dim sh As Worksheet
Dim s()      '시트이름이 '메인''외우기'가 아닌 시트 이름을 각각 보관할 배열방..동적배열적용
Dim i As Long

For Each sh In ThisWorkbook.Worksheets
      If sh.Name = "메인" Then
      ElseIf sh.Name = "외우기" Then
      Else
            ReDim Preserve s(i)
            s(i) = sh.Name   '각각의 s방에 숨길 시트 이름 보관
            i = i + 1
      End If
Next

Sheets(s).Visible = False

End Sub

 

For Each~Next문에 동적배열을 같이 적용하면 속도가 향상된다.

vba#25.xlsm
0.02MB

 

 

https://www.youtube.com/watch?v=HIlFL8yniM4&list=PLfxvqpVCYZ8e0qlyc_FU46neoWjO7yTWj&index=25

 

 

  Comments,     Trackbacks
최근 작성 글
최근 작성 댓글
최근 작성 트랙백
프로필
공지사항
글 보관함
캘린더
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
TODAY TOTAL