Below is a quick sample of my code that I have in my workbook. Not all the tabs are the same so for example I want the Macro to do specific things to the "MTD Glance" tab and a couple other tabs, but in the middle of my code, I have a sample of my daily tabs which are numbered "01" thru "31" and they do not change. My code repeats 31 times for those sections because I do not know how to isolate the loop to only those specific tabs "01" thru "31". Could someone please help me identify a loop to do just those sections?
I have other loops like "unprotect" in the document, but that goes throughout the entire document so I have no problems. Please help. Thanks.
On a side note, my autofilter is running a bit slow, but I feel that it is just all my conditional formatting, so I'll fix that after my loop problem.
I have other loops like "unprotect" in the document, but that goes throughout the entire document so I have no problems. Please help. Thanks.
On a side note, my autofilter is running a bit slow, but I feel that it is just all my conditional formatting, so I'll fix that after my loop problem.
Code:
'Each tab gets its own autofilterSheets("MTD Glance").Select
Worksheets("MTD Glance").Calculate
'Unfilters all rows
Sheets("MTD Glance").Select
ActiveSheet.AutoFilterMode = False
Sheets("MTD Glance").Select
Cells.EntireRow.Hidden = False
'Filters the data using autofilter
Sheets("MTD Glance").Select
Range("A:A").AutoFilter
Range("A:A").AutoFilter field:=1, Criteria1:="<>0"
'End Auto filter for tab
Sheets("MTD Glance").Select
Application.GoTo Reference:=Range("D1"), Scroll:=True
'Start worksheet code: Each tab gets its own autofilter
'Unfilters all rows
Sheets("01").Select
Worksheets("01").Calculate
ActiveSheet.AutoFilterMode = False
Cells.EntireRow.Hidden = False
'Filters the data using autofilter
Sheets("01").Select
Range("A:A").AutoFilter
Range("A:A").AutoFilter field:=1, Criteria1:="<>0"
'End Auto filter for tab
'Unhide + Hide Columns False = Unhide, True = Hide
'Cells.EntireColumn.Hidden = False
'Unhide Columns
Sheets("01").Select
Cells.EntireColumn.Hidden = False
Sheets("01").Select
If Range("B1").Value <= "3" Then
ActiveSheet.Cells.EntireColumn.Hidden = False
Columns("P:X").EntireColumn.Hidden = True
Columns("AO:BD").EntireColumn.Hidden = True
ElseIf Range("B1").Value = "4" Then
ActiveSheet.Cells.EntireColumn.Hidden = False
Columns("R:X").EntireColumn.Hidden = True
Columns("AS:BD").EntireColumn.Hidden = True
ElseIf Range("B1").Value = "5" Then
ActiveSheet.Cells.EntireColumn.Hidden = False
Columns("T:X").EntireColumn.Hidden = True
Columns("AW:BD").EntireColumn.Hidden = True
ElseIf Range("B1").Value = "6" Then
ActiveSheet.Cells.EntireColumn.Hidden = False
Columns("V:X").EntireColumn.Hidden = True
Columns("BA:BD").EntireColumn.Hidden = True
ElseIf Range("B1").Value = "7" Then
ActiveSheet.Cells.EntireColumn.Hidden = False
End If
'Hide Columns
Sheets("01").Select
Columns("A:H").Select
Selection.EntireColumn.Hidden = True
Sheets("01").Select
Columns("BE:BM").Select
Selection.EntireColumn.Hidden = True
Application.GoTo Reference:=Range("H1"), Scroll:=True
'EndWorksheet Code
'Start worksheet code: Each tab gets its own autofilter
'Unfilters all rows
Sheets("02").Select
Worksheets("02").Calculate
ActiveSheet.AutoFilterMode = False
Cells.EntireRow.Hidden = False
'Filters the data using autofilter
Sheets("02").Select
Range("A:A").AutoFilter
Range("A:A").AutoFilter field:=1, Criteria1:="<>0"
'End Auto filter for tab
'Unhide + Hide Columns False = Unhide, True = Hide
'Cells.EntireColumn.Hidden = False
'Unhide Columns
Sheets("02").Select
Cells.EntireColumn.Hidden = False
Sheets("02").Select
If Range("B1").Value <= "3" Then
ActiveSheet.Cells.EntireColumn.Hidden = False
Columns("P:X").EntireColumn.Hidden = True
Columns("AO:BD").EntireColumn.Hidden = True
ElseIf Range("B1").Value = "4" Then
ActiveSheet.Cells.EntireColumn.Hidden = False
Columns("R:X").EntireColumn.Hidden = True
Columns("AS:BD").EntireColumn.Hidden = True
ElseIf Range("B1").Value = "5" Then
ActiveSheet.Cells.EntireColumn.Hidden = False
Columns("T:X").EntireColumn.Hidden = True
Columns("AW:BD").EntireColumn.Hidden = True
ElseIf Range("B1").Value = "6" Then
ActiveSheet.Cells.EntireColumn.Hidden = False
Columns("V:X").EntireColumn.Hidden = True
Columns("BA:BD").EntireColumn.Hidden = True
ElseIf Range("B1").Value = "7" Then
ActiveSheet.Cells.EntireColumn.Hidden = False
End If
'Hide Columns
Sheets("02").Select
Columns("A:H").Select
Selection.EntireColumn.Hidden = True
Sheets("02").Select
Columns("BE:BM").Select
Selection.EntireColumn.Hidden = True
Application.GoTo Reference:=Range("H1"), Scroll:=True
'EndWorksheet Code
Last edited by a moderator: