Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50112

Macro to consolidate data from multiple sheets to one

$
0
0
hey all

i have the following macro, however I am struggling to make it work on my file:

Code:

Private Sub Worksheet_Activate()
Dim Sh As Worksheet
Dim Newsh As Worksheet
Dim LR As Long, NR As Long

Application.ScreenUpdating = False

Set Newsh = ThisWorkbook.Sheets(Sheet1.Name)
Newsh.Range("A1").CurrentRegion.Offset(1).Clear
NR = 9

   
    For Each Sh In ThisWorkbook.Worksheets
        If Sh.Name Like "*" And Sh.Name <> Sheet1.Name And Sh.Visible Then
            LR = Sh.Range("B" & Sh.Rows.Count).End(xlUp).Row
            If LR > 8 Then
                Sh.Range("A2:U" & LR).Copy
                Newsh.Range("C" & NR).PasteSpecial xlPasteValues
                Newsh.Range("C" & NR).PasteSpecial xlPasteAll
                LR = Newsh.Range("C" & Rows.Count).End(xlUp).Row
                Newsh.Range("B" & NR, "B" & LR) = Sh.Name
                NR = LR + 1
 
            End If
        End If
    Next Sh

    If NR > 9 Then
    Range("A2:A" & NR - 1).Formula = "=row(A1)"
    End If
   
 
    With Newsh.Range("A1").CurrentRegion.Font
        .Name = "Arial"
        .Size = 8
    End With
       

Application.ScreenUpdating = True
End Sub

i have attached my sample. essentially i have the dec, jan etc month tabs to consolidate into the summary sheet. i would like the data to be dumped from both sheets into the summary sheets. i will be adding a feb, march, april etc tabs as the year progresses.

i would also like column A in the summary sheet to repeat the name of the sheet the data is being retrieved from.

pls help..not sure what the issue with the macro above is :S
Attached Files

Viewing all articles
Browse latest Browse all 50112

Trending Articles