Need to make Loop in Worksheet & Workbook

Sangampmishra

New Member
Joined
May 23, 2018
Messages
3
I am new in VBA & start to learn it.
I have Workbook name Primary Flash (MTD & YTD) and this Workbook have 6 Sheets and in all sheets, there are North, West, East & South Zone Data in Field (Region)
I need to filter data from every sheets from Zone wise & paste in Anther Workbooks where same 6 sheets available.

''code for 1 sheet & copy paste code and change sheet name to run for all sheet. then copy all code & change file name & Region name to work in all workbooks & all sheets.

Now pls help me it to short the code & keep it in loop.

[TABLE="width: 766"]
<tbody>[TR]
[TD][TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 75"]
<tbody>[TR]
[TD="class: xl67, width: 75"]REGION[/TD]
[/TR]
[TR]
[TD="class: xl67, width: 75"][/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 103"]
<tbody>[TR]
[TD="class: xl67, width: 103"]BSM[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 49"]
<tbody>[TR]
[TD="class: xl67, width: 49"]1-31 May'17[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 42"]
<tbody>[TR]
[TD="class: xl67, width: 42"]MTD May'18[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 52"]
<tbody>[TR]
[TD="class: xl67, width: 52"]MTD % Gr[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 47"]
<tbody>[TR]
[TD="class: xl67, width: 47"]YTD May'17[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 52"]
<tbody>[TR]
[TD="class: xl67, width: 52"]YTD May'18[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 48"]
<tbody>[TR]
[TD="class: xl67, width: 48"]YTD % Gr[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Like 30 more Columns[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]East[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]West[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]North[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]South[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Below are the Code
Code:
Sub Primary()
    
    


''Open main file and unhide all columns.
      
Application.DisplayAlerts = False
Sheets("BSM BM").Select
'Rows("17:30").Delete
Range("D:E,M:N,V:W,AE:AF,AN:AO").EntireColumn.Hidden = False
Sheets("ASM").Select
Range("F:G,O:P,X:Y,AG:AH,AP:AW").EntireColumn.Hidden = False
Sheets("DSE").Select
Range("H:I,Q:R,Z:AA,AI:AJ,AR:AS").EntireColumn.Hidden = False
Sheets("DB").Select
Range("K:L,T:U,AC:AD,AL:AM,AU:AV").EntireColumn.Hidden = False
Sheets("Channel").Select
Range("G:H,P:Q,Y:Z").EntireColumn.Hidden = False
  
''code for 1 sheet & copy paste code and change sheet name to run for all sheet. then copy all code & change file name & Region name to work in all workbooks & all sheets.


    Workbooks.Open Filename:="C:\Users\ext-smma\Desktop\Zone\Primary Flash (MTD & YTD) - East.xlsx"
    Windows("Primary Flash (MTD & YTD) - East.xlsx").Activate
    Worksheets("BSM BM").Range("B4:AY30").ClearContents
    Range("D:E,M:N,V:W,AE:AF,AN:AO").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("BSM BM").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$AU$20").AutoFilter Field:=1, Criteria1:="=EAST", _
        Operator:=xlOr, Criteria2:="=EAST Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - East.xlsx").Activate
    Sheets("BSM BM").Select
    Range("B3").Select
    ActiveSheet.Paste
    Range("D:E,M:N,V:W,AE:AF,AN:AO").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter




    
    
    Windows("Primary Flash (MTD & YTD) - East.xlsx").Activate
    Worksheets("ASM").Range("B4:AW100").ClearContents
    Range("F:G,O:P,X:Y,AG:AH,AP:AW").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("ASM").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$AW$100").AutoFilter Field:=1, Criteria1:="=EAST", _
        Operator:=xlOr, Criteria2:="=EAST Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - East.xlsx").Activate
    Sheets("ASM").Select
    Range("B3").Select
    ActiveSheet.Paste
    Range("F:G,O:P,X:Y,AG:AH,AP:AW").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    On Error Resume Next
    With Range("B4:B500")
    .Value = .Value
    .SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
    
    
    Windows("Primary Flash (MTD & YTD) - East.xlsx").Activate
    Worksheets("DSE").Range("B4:AY500").ClearContents
    Range("H:I,Q:R,Z:AA,AI:AJ,AR:AS").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("DSE").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$AY$500").AutoFilter Field:=1, Criteria1:="=EAST", _
        Operator:=xlOr, Criteria2:="=EAST Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - East.xlsx").Activate
    Sheets("DSE").Select
    Range("B3 ").Select
    ActiveSheet.Paste
    Range("H:I,Q:R,Z:AA,AI:AJ,AR:AS").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    On Error Resume Next
    With Range("B4:B500")
    .Value = .Value
    .SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
    
    
    Windows("Primary Flash (MTD & YTD) - East.xlsx").Activate
    Worksheets("DB").Range("B4:BB5000").ClearContents
    Range("K:L,T:U,AC:AD,AL:AM,AU:AV").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("DB").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$BB$5000").AutoFilter Field:=1, Criteria1:="=EAST", _
        Operator:=xlOr, Criteria2:="=EAST Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - East.xlsx").Activate
    Sheets("DB").Select
    Range("B3 ").Select
    ActiveSheet.Paste
    Range("K:L,T:U,AC:AD,AL:AM,AU:AV").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    On Error Resume Next
    With Range("B4:B5000")
    .Value = .Value
    .SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
    
    Windows("Primary Flash (MTD & YTD) - East.xlsx").Activate
    Worksheets("Brand").Range("A3:AJ500").ClearContents
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("Brand").Select
    Range("A2").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$2:$AJ$500").AutoFilter Field:=1, Criteria1:="=EAST", _
        Operator:=xlOr, Criteria2:="=EAST Total"
    Range("A2").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - East.xlsx").Activate
    Sheets("Brand").Select
    Range("A2 ").Select
    ActiveSheet.Paste
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    Windows("Primary Flash (MTD & YTD) - East.xlsx").Activate
    Worksheets("Channel").Range("A4:AF500").ClearContents
    Range("G:H,P:Q,Y:Z").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("Channel").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$3:$AF$500").AutoFilter Field:=1, Criteria1:="=EAST", _
        Operator:=xlOr, Criteria2:="=EAST Total"
    Range("A3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - East.xlsx").Activate
    Sheets("Channel").Select
    Range("A3").Select
    ActiveSheet.Paste
    Range("G:H,P:Q,Y:Z").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    On Error Resume Next
    With Range("A4:A1000")
    .Value = .Value
    .SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
    
    Windows("Primary Flash (MTD & YTD) - East.xlsx").Activate
    ActiveWorkbook.Save
    ActiveWindow.Close








Workbooks.Open Filename:="C:\Users\ext-smma\Desktop\Zone\Primary Flash (MTD & YTD) - West.xlsx"
    Windows("Primary Flash (MTD & YTD) - West.xlsx").Activate
    Worksheets("BSM BM").Range("B4:AY30").ClearContents
    Range("D:E,M:N,V:W,AE:AF,AN:AO").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("BSM BM").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$AU$20").AutoFilter Field:=1, Criteria1:="=WEST", _
        Operator:=xlOr, Criteria2:="=WEST Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - West.xlsx").Activate
    Sheets("BSM BM").Select
    Range("B3").Select
    ActiveSheet.Paste
    Range("D:E,M:N,V:W,AE:AF,AN:AO").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    
    Windows("Primary Flash (MTD & YTD) - West.xlsx").Activate
    Worksheets("ASM").Range("B4:AW100").ClearContents
    Range("F:G,O:P,X:Y,AG:AH,AP:AW").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("ASM").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$AW$100").AutoFilter Field:=1, Criteria1:="=WEST", _
        Operator:=xlOr, Criteria2:="=WEST Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - West.xlsx").Activate
    Sheets("ASM").Select
    Range("B3").Select
    ActiveSheet.Paste
    Range("F:G,O:P,X:Y,AG:AH,AP:AW").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    
    Windows("Primary Flash (MTD & YTD) - West.xlsx").Activate
    Worksheets("DSE").Range("B4:AY500").ClearContents
    Range("H:I,Q:R,Z:AA,AI:AJ,AR:AS").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("DSE").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$AY$500").AutoFilter Field:=1, Criteria1:="=WEST", _
        Operator:=xlOr, Criteria2:="=WEST Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - West.xlsx").Activate
    Sheets("DSE").Select
    Range("B3 ").Select
    ActiveSheet.Paste
    Range("H:I,Q:R,Z:AA,AI:AJ,AR:AS").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    
    Windows("Primary Flash (MTD & YTD) - West.xlsx").Activate
    Worksheets("DB").Range("B4:BB5000").ClearContents
    Range("K:L,T:U,AC:AD,AL:AM,AU:AV").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("DB").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$BB$5000").AutoFilter Field:=1, Criteria1:="=WEST", _
        Operator:=xlOr, Criteria2:="=WEST Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - West.xlsx").Activate
    Sheets("DB").Select
    Range("B3 ").Select
    ActiveSheet.Paste
    Range("K:L,T:U,AC:AD,AL:AM,AU:AV").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    Windows("Primary Flash (MTD & YTD) - West.xlsx").Activate
    Worksheets("Brand").Range("A3:AJ500").ClearContents
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("Brand").Select
    Range("A2").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$2:$AJ$500").AutoFilter Field:=1, Criteria1:="=WEST", _
        Operator:=xlOr, Criteria2:="=WEST Total"
    Range("A2").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - West.xlsx").Activate
    Sheets("Brand").Select
    Range("A2 ").Select
    ActiveSheet.Paste
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    Windows("Primary Flash (MTD & YTD) - West.xlsx").Activate
    Worksheets("Channel").Range("A4:AF500").ClearContents
    Range("G:H,P:Q,Y:Z").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("Channel").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$3:$AF$500").AutoFilter Field:=1, Criteria1:="=WEST", _
        Operator:=xlOr, Criteria2:="=WEST Total"
    Range("A3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - West.xlsx").Activate
    Sheets("Channel").Select
    Range("A3").Select
    ActiveSheet.Paste
    Range("G:H,P:Q,Y:Z").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    Windows("Primary Flash (MTD & YTD) - West.xlsx").Activate
    ActiveWorkbook.Save
    ActiveWindow.Close








Workbooks.Open Filename:="C:\Users\ext-smma\Desktop\Zone\Primary Flash (MTD & YTD) - South.xlsx"
    Windows("Primary Flash (MTD & YTD) - South.xlsx").Activate
    Worksheets("BSM BM").Range("B4:AY30").ClearContents
    Range("D:E,M:N,V:W,AE:AF,AN:AO").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("BSM BM").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$AU$20").AutoFilter Field:=1, Criteria1:="=SOUTH", _
        Operator:=xlOr, Criteria2:="=SOUTH Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - South.xlsx").Activate
    Sheets("BSM BM").Select
    Range("B3").Select
    ActiveSheet.Paste
    Range("D:E,M:N,V:W,AE:AF,AN:AO").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    
    Windows("Primary Flash (MTD & YTD) - South.xlsx").Activate
    Worksheets("ASM").Range("B4:AW100").ClearContents
    Range("F:G,O:P,X:Y,AG:AH,AP:AW").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("ASM").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$AW$100").AutoFilter Field:=1, Criteria1:="=SOUTH", _
        Operator:=xlOr, Criteria2:="=SOUTH Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - South.xlsx").Activate
    Sheets("ASM").Select
    Range("B3").Select
    ActiveSheet.Paste
    Range("F:G,O:P,X:Y,AG:AH,AP:AW").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    
    Windows("Primary Flash (MTD & YTD) - South.xlsx").Activate
    Worksheets("DSE").Range("B4:AY500").ClearContents
    Range("H:I,Q:R,Z:AA,AI:AJ,AR:AS").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("DSE").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$AY$500").AutoFilter Field:=1, Criteria1:="=SOUTH", _
        Operator:=xlOr, Criteria2:="=SOUTH Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - South.xlsx").Activate
    Sheets("DSE").Select
    Range("B3 ").Select
    ActiveSheet.Paste
    Range("H:I,Q:R,Z:AA,AI:AJ,AR:AS").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    
    Windows("Primary Flash (MTD & YTD) - South.xlsx").Activate
    Worksheets("DB").Range("B4:BB5000").ClearContents
    Range("K:L,T:U,AC:AD,AL:AM,AU:AV").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("DB").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$BB$5000").AutoFilter Field:=1, Criteria1:="=SOUTH", _
        Operator:=xlOr, Criteria2:="=SOUTH Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - South.xlsx").Activate
    Sheets("DB").Select
    Range("B3 ").Select
    ActiveSheet.Paste
    Range("K:L,T:U,AC:AD,AL:AM,AU:AV").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    Windows("Primary Flash (MTD & YTD) - South.xlsx").Activate
    Worksheets("Brand").Range("A3:AJ500").ClearContents
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("Brand").Select
    Range("A2").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$2:$AJ$500").AutoFilter Field:=1, Criteria1:="=SOUTH", _
        Operator:=xlOr, Criteria2:="=SOUTH Total"
    Range("A2").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - South.xlsx").Activate
    Sheets("Brand").Select
    Range("A2 ").Select
    ActiveSheet.Paste
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    Windows("Primary Flash (MTD & YTD) - South.xlsx").Activate
    Worksheets("Channel").Range("A4:AF500").ClearContents
    Range("G:H,P:Q,Y:Z").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("Channel").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$3:$AF$500").AutoFilter Field:=1, Criteria1:="=SOUTH", _
        Operator:=xlOr, Criteria2:="=SOUTH Total"
    Range("A3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - South.xlsx").Activate
    Sheets("Channel").Select
    Range("A3").Select
    ActiveSheet.Paste
    Range("G:H,P:Q,Y:Z").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    Windows("Primary Flash (MTD & YTD) - South.xlsx").Activate
    ActiveWorkbook.Save
    ActiveWindow.Close






Workbooks.Open Filename:="C:\Users\ext-smma\Desktop\Zone\Primary Flash (MTD & YTD) - North.xlsx"
    Windows("Primary Flash (MTD & YTD) - North.xlsx").Activate
    Worksheets("BSM BM").Range("B4:AY30").ClearContents
    Range("D:E,M:N,V:W,AE:AF,AN:AO").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("BSM BM").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$AU$20").AutoFilter Field:=1, Criteria1:="=NORTH", _
        Operator:=xlOr, Criteria2:="=NORTH Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - North.xlsx").Activate
    Sheets("BSM BM").Select
    Range("B3").Select
    ActiveSheet.Paste
    Range("D:E,M:N,V:W,AE:AF,AN:AO").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    
    Windows("Primary Flash (MTD & YTD) - North.xlsx").Activate
    Worksheets("ASM").Range("B4:AW100").ClearContents
    Range("F:G,O:P,X:Y,AG:AH,AP:AW").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("ASM").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$AW$100").AutoFilter Field:=1, Criteria1:="=NORTH", _
        Operator:=xlOr, Criteria2:="=NORTH Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - North.xlsx").Activate
    Sheets("ASM").Select
    Range("B3").Select
    ActiveSheet.Paste
    Range("F:G,O:P,X:Y,AG:AH,AP:AW").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    
    Windows("Primary Flash (MTD & YTD) - North.xlsx").Activate
    Worksheets("DSE").Range("B4:AY500").ClearContents
    Range("H:I,Q:R,Z:AA,AI:AJ,AR:AS").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("DSE").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$AY$500").AutoFilter Field:=1, Criteria1:="=NORTH", _
        Operator:=xlOr, Criteria2:="=NORTH Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - North.xlsx").Activate
    Sheets("DSE").Select
    Range("B3 ").Select
    ActiveSheet.Paste
    Range("H:I,Q:R,Z:AA,AI:AJ,AR:AS").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    
    Windows("Primary Flash (MTD & YTD) - North.xlsx").Activate
    Worksheets("DB").Range("B4:BB5000").ClearContents
    Range("K:L,T:U,AC:AD,AL:AM,AU:AV").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("DB").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$3:$BB$5000").AutoFilter Field:=1, Criteria1:="=NORTH", _
        Operator:=xlOr, Criteria2:="=NORTH Total"
    Range("B3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - North.xlsx").Activate
    Sheets("DB").Select
    Range("B3 ").Select
    ActiveSheet.Paste
    Range("K:L,T:U,AC:AD,AL:AM,AU:AV").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    Windows("Primary Flash (MTD & YTD) - North.xlsx").Activate
    Worksheets("Brand").Range("A3:AJ500").ClearContents
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("Brand").Select
    Range("A2").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$2:$AJ$500").AutoFilter Field:=1, Criteria1:="=NORTH", _
        Operator:=xlOr, Criteria2:="=NORTH Total"
    Range("A2").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - North.xlsx").Activate
    Sheets("Brand").Select
    Range("A2 ").Select
    ActiveSheet.Paste
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    Windows("Primary Flash (MTD & YTD) - North.xlsx").Activate
    Worksheets("Channel").Range("A4:AF500").ClearContents
    Range("G:H,P:Q,Y:Z").EntireColumn.Hidden = False
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("Channel").Select
    Range("B3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$3:$AF$500").AutoFilter Field:=1, Criteria1:="=NORTH", _
        Operator:=xlOr, Criteria2:="=NORTH Total"
    Range("A3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("Primary Flash (MTD & YTD) - North.xlsx").Activate
    Sheets("Channel").Select
    Range("A3").Select
    ActiveSheet.Paste
    Range("G:H,P:Q,Y:Z").EntireColumn.Hidden = True
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Selection.AutoFilter
    
    Windows("Primary Flash (MTD & YTD) - North.xlsx").Activate
    ActiveWorkbook.Save
    ActiveWindow.Close
    
    Windows("Primary Flash (MTD & YTD).xlsx").Activate
    Sheets("BSM BM").Select
    Range("D:E,M:N,V:W,AE:AF,AN:AO").EntireColumn.Hidden = True
    Sheets("ASM").Select
    Range("F:G,O:P,X:Y,AG:AH,AP:AW").EntireColumn.Hidden = True
    Sheets("DSE").Select
    Range("H:I,Q:R,Z:AA,AI:AJ,AR:AS").EntireColumn.Hidden = True
    Sheets("DB").Select
    Range("K:L,T:U,AC:AD,AL:AM,AU:AV").EntireColumn.Hidden = True
    Sheets("Channel").Select
    Range("G:H,P:Q,Y:Z").EntireColumn.Hidden = True
    ActiveWorkbook.Save
    
    
End Sub
 
Last edited by a moderator:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I know it is quite difficult to read so long code but this is only 15-20 line code, I don't looping so repeating code for every workbook & every worksheets.:)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top