Hi all,
I was hoping someone could help me with some loop code for below consolidation macro.
My workbook has a "Consolidation" tab and several country tabs (all same format). My code consolidates all of the individual country tabs (after a filter is applied), one below the other in the consolidation tab.
Below code works for 2 countries but there will be 20+ country tabs.
I'm hoping someone can tweak my code so it can loop through all the country tabs rather than having to duplicate the code over and over like below.
Sub Consolidate()
Set CONS = Sheets("Consolidation")
Set DEN = Sheets("Denmark")
Set SPA = Sheets("Spain")
'Denmark
LR = DEN.Range("B" & Rows.Count).End(xlUp).Row
DEN.Range("B9:CQ" & LR).AutoFilter Field:=94, Criteria1:="Data"
LR = DEN.Range("B" & Rows.Count).End(xlUp).Row
DEN.Range("B10:CQ" & LR).Copy
CONS.Range("A2").PasteSpecial xlPasteValues
'Spain
LR = SPA.Range("B" & Rows.Count).End(xlUp).Row
SPA.Range("B9:CQ" & LR).AutoFilter Field:=94, Criteria1:="Data"
LR = SPA.Range("B" & Rows.Count).End(xlUp).Row
SPA.Range("B10:CQ" & LR).Copy
LR = CONS.Range("B" & Rows.Count).End(xlUp).Row
CONS.Range("A" & LR + 1).PasteSpecial xlPasteValues
End Sub
Bookmarks