VBA - find Data from latest Date and copy into one Sheet

iris1007

New Member
Joined
Jun 28, 2017
Messages
31
Hi,
I have a lot of Data from many Sheets and I would like to use VBA to auto consolidate the latest Month Data into one Summary Sheet.  

Below are some sample data: 

[TABLE="width: 793"]
<tbody>[TR]
[TD]Sheet1[/TD]
[TD="colspan: 2"]May-17[/TD]
[TD="colspan: 2"]Jun-17[/TD]
[TD="colspan: 2"]Jul-17[/TD]
[TD="colspan: 2"]Aug-17[/TD]
[TD="colspan: 2"]Sep-17[/TD]
[/TR]
[TR]
[TD]PARTs[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[/TR]
[TR]
[TD]JC01[/TD]
[TD]160.15[/TD]
[TD]$1,263.58[/TD]
[TD]280.00[/TD]
[TD]$3,514.00[/TD]
[TD]32.00[/TD]
[TD]$401.60[/TD]
[TD]16.00[/TD]
[TD]$126.24[/TD]
[TD]29.00[/TD]
[TD]$363.95[/TD]
[/TR]
[TR]
[TD]JC02[/TD]
[TD]71.00[/TD]
[TD]$560.19[/TD]
[TD]329.98[/TD]
[TD]$4,141.25[/TD]
[TD]28.00[/TD]
[TD]$351.40[/TD]
[TD]18.00[/TD]
[TD]$142.02[/TD]
[TD]20.50[/TD]
[TD]$257.28[/TD]
[/TR]
[TR]
[TD]JC03[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD]60.00[/TD]
[TD]$753.00[/TD]
[TD]31.00[/TD]
[TD]$389.05[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD]3.00[/TD]
[TD]$37.65[/TD]
[/TR]
[TR]
[TD]JC04[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD]18.00[/TD]
[TD]$225.90[/TD]
[TD]70.00[/TD]
[TD]$878.50[/TD]
[TD]28.00[/TD]
[TD]$220.92[/TD]
[TD]8.00[/TD]
[TD]$100.40[/TD]
[/TR]
[TR]
[TD]JC05[/TD]
[TD]20.00[/TD]
[TD]$157.80[/TD]
[TD]112.00[/TD]
[TD]$1,405.60[/TD]
[TD]12.00[/TD]
[TD]$150.60[/TD]
[TD]6.00[/TD]
[TD]$47.34[/TD]
[TD]2.00[/TD]
[TD]$25.10[/TD]
[/TR]
[TR]
[TD]JC06[/TD]
[TD]11.00[/TD]
[TD]$86.79[/TD]
[TD] [/TD]
[TD]$0.00[/TD]
[TD]17.00[/TD]
[TD]$213.35[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[/TR]
[TR]
[TD]JC07[/TD]
[TD]55.00[/TD]
[TD]$433.95[/TD]
[TD] [/TD]
[TD]$0.00[/TD]
[TD]20.00[/TD]
[TD]$251.00[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD]2.00[/TD]
[TD]$25.10[/TD]
[/TR]
[TR]
[TD]JC08[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD] [/TD]
[TD]$0.00[/TD]
[TD]21.00[/TD]
[TD]$263.55[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD]10.00[/TD]
[TD]$125.50[/TD]
[/TR]
</tbody><colgroup><col><col><col><col><col><col span="6"></colgroup>[/TABLE]


[TABLE="width: 793"]
<tbody>[TR]
[TD]Sheet2[/TD]
[TD="colspan: 2"]May-17[/TD]
[TD="colspan: 2"]Jun-17[/TD]
[TD="colspan: 2"]Jul-17[/TD]
[TD="colspan: 2"]Aug-17[/TD]
[TD="colspan: 2"]Sep-17[/TD]
[/TR]
[TR]
[TD]PARTs[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[/TR]
[TR]
[TD]99D01[/TD]
[TD]33.00[/TD]
[TD]$214.50[/TD]
[TD]30.00[/TD]
[TD]$267.00[/TD]
[TD]34.00[/TD]
[TD]$302.60[/TD]
[TD]38.00[/TD]
[TD]$247.00[/TD]
[TD]7.00[/TD]
[TD]$45.50[/TD]
[/TR]
[TR]
[TD]99D02[/TD]
[TD]31.00[/TD]
[TD]$201.50[/TD]
[TD]30.00[/TD]
[TD]$267.00[/TD]
[TD]32.00[/TD]
[TD]$284.80[/TD]
[TD]2.00[/TD]
[TD]$13.00[/TD]
[TD]7.00[/TD]
[TD]$45.50[/TD]
[/TR]
[TR]
[TD]99D03[/TD]
[TD]32.00[/TD]
[TD]$208.00[/TD]
[TD]27.00[/TD]
[TD]$240.30[/TD]
[TD]35.00[/TD]
[TD]$311.50[/TD]
[TD]5.00[/TD]
[TD]$32.50[/TD]
[TD]34.00[/TD]
[TD]$221.00[/TD]
[/TR]
[TR]
[TD]99D04[/TD]
[TD]33.00[/TD]
[TD]$214.50[/TD]
[TD]29.00[/TD]
[TD]$258.10[/TD]
[TD]23.00[/TD]
[TD]$204.70[/TD]
[TD]13.00[/TD]
[TD]$84.50[/TD]
[TD]32.00[/TD]
[TD]$208.00[/TD]
[/TR]
[TR]
[TD]99D05[/TD]
[TD]32.00[/TD]
[TD]$208.00[/TD]
[TD]29.00[/TD]
[TD]$258.10[/TD]
[TD]73.00[/TD]
[TD]$649.70[/TD]
[TD]15.00[/TD]
[TD]$97.50[/TD]
[TD]36.00[/TD]
[TD]$234.00[/TD]
[/TR]
[TR]
[TD]99D06[/TD]
[TD]32.00[/TD]
[TD]$208.00[/TD]
[TD]29.00[/TD]
[TD]$258.10[/TD]
[TD]5.00[/TD]
[TD]$44.50[/TD]
[TD]8.00[/TD]
[TD]$52.00[/TD]
[TD]42.00[/TD]
[TD]$273.00[/TD]
[/TR]
[TR]
[TD]99D07[/TD]
[TD]36.00[/TD]
[TD]$234.00[/TD]
[TD]30.00[/TD]
[TD]$267.00[/TD]
[TD]63.00[/TD]
[TD]$560.70[/TD]
[TD]6.00[/TD]
[TD]$39.00[/TD]
[TD]5.00[/TD]
[TD]$32.50[/TD]
[/TR]
[TR]
[TD]99D08[/TD]
[TD]33.00[/TD]
[TD]$214.50[/TD]
[TD]30.00[/TD]
[TD]$267.00[/TD]
[TD]48.00[/TD]
[TD]$427.20[/TD]
[TD]6.00[/TD]
[TD]$39.00[/TD]
[TD]2.00[/TD]
[TD]$13.00[/TD]
[/TR]
[TR]
[TD]99D09[/TD]
[TD]18.00[/TD]
[TD]$117.00[/TD]
[TD]30.00[/TD]
[TD]$267.00[/TD]
[TD]75.00[/TD]
[TD]$667.50[/TD]
[TD]53.00[/TD]
[TD]$344.50[/TD]
[TD]34.00[/TD]
[TD]$221.00[/TD]
[/TR]
[TR]
[TD]99D10[/TD]
[TD]39.00[/TD]
[TD]$253.50[/TD]
[TD]29.00[/TD]
[TD]$258.10[/TD]
[TD]50.00[/TD]
[TD]$445.00[/TD]
[TD]47.00[/TD]
[TD]$305.50[/TD]
[TD]34.00[/TD]
[TD]$221.00[/TD]
[/TR]
[TR]
[TD]99D11[/TD]
[TD]32.00[/TD]
[TD]$208.00[/TD]
[TD]30.00[/TD]
[TD]$267.00[/TD]
[TD]8.00[/TD]
[TD]$71.20[/TD]
[TD]8.00[/TD]
[TD]$52.00[/TD]
[TD]45.00[/TD]
[TD]$292.50[/TD]
[/TR]
[TR]
[TD]99D12[/TD]
[TD]39.00[/TD]
[TD]$253.50[/TD]
[TD]35.00[/TD]
[TD]$311.50[/TD]
[TD]9.00[/TD]
[TD]$80.10[/TD]
[TD]6.00[/TD]
[TD]$39.00[/TD]
[TD]6.00[/TD]
[TD]$39.00[/TD]
[/TR]
[TR]
[TD]99D13[/TD]
[TD]22.00[/TD]
[TD]$143.00[/TD]
[TD]22.00[/TD]
[TD]$195.80[/TD]
[TD]17.00[/TD]
[TD]$151.30[/TD]
[TD]10.00[/TD]
[TD]$65.00[/TD]
[TD]41.00[/TD]
[TD]$266.50[/TD]
[/TR]
[TR]
[TD]99D14[/TD]
[TD]25.00[/TD]
[TD]$162.50[/TD]
[TD]29.00[/TD]
[TD]$258.10[/TD]
[TD]50.00[/TD]
[TD]$445.00[/TD]
[TD]52.00[/TD]
[TD]$338.00[/TD]
[TD]8.00[/TD]
[TD]$52.00[/TD]
[/TR]
</tbody><colgroup><col><col><col><col><col><col span="6"></colgroup>[/TABLE]

[TABLE="width: 1177"]
<tbody>[TR]
[TD]Sheet3[/TD]
[TD="colspan: 2"]Feb-17[/TD]
[TD="colspan: 2"]Mar-17[/TD]
[TD="colspan: 2"]Apr-17[/TD]
[TD="colspan: 2"]May-17[/TD]
[TD="colspan: 2"]Jun-17[/TD]
[TD="colspan: 2"]Jul-17[/TD]
[TD="colspan: 2"]Aug-17[/TD]
[TD="colspan: 2"]Sep-17[/TD]
[/TR]
[TR]
[TD]PARTs[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[TD]Tatal Quantity[/TD]
[TD]price[/TD]
[/TR]
[TR]
[TD]HV01[/TD]
[TD]30.00[/TD]
[TD]$173.67[/TD]
[TD]6.00[/TD]
[TD]$58.45[/TD]
[TD]23.00[/TD]
[TD]$224.07[/TD]
[TD]28.00[/TD]
[TD]$314.86[/TD]
[TD]36.00[/TD]
[TD]$183.60[/TD]
[TD]15.00[/TD]
[TD]$76.50[/TD]
[TD]27.00[/TD]
[TD]$300.24[/TD]
[TD]24.00[/TD]
[TD]$196.21[/TD]
[/TR]
[TR]
[TD]HV02[/TD]
[TD]28.00[/TD]
[TD]$162.09[/TD]
[TD]27.00[/TD]
[TD]$263.03[/TD]
[TD]5.00[/TD]
[TD]$48.71[/TD]
[TD]25.00[/TD]
[TD]$281.13[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD]32.00[/TD]
[TD]$163.20[/TD]
[TD]27.00[/TD]
[TD]$300.24[/TD]
[TD]26.00[/TD]
[TD]$212.56[/TD]
[/TR]
[TR]
[TD]HV03[/TD]
[TD]41.00[/TD]
[TD]$237.35[/TD]
[TD]60.00[/TD]
[TD]$584.52[/TD]
[TD]28.00[/TD]
[TD]$272.78[/TD]
[TD]14.00[/TD]
[TD]$157.43[/TD]
[TD]35.00[/TD]
[TD]$178.50[/TD]
[TD]32.00[/TD]
[TD]$163.20[/TD]
[TD]19.00[/TD]
[TD]$211.28[/TD]
[TD]30.00[/TD]
[TD]$245.26[/TD]
[/TR]
[TR]
[TD]HV04[/TD]
[TD]12.00[/TD]
[TD]$69.47[/TD]
[TD]23.00[/TD]
[TD]$224.07[/TD]
[TD]2.00[/TD]
[TD]$19.48[/TD]
[TD]25.00[/TD]
[TD]$281.13[/TD]
[TD]22.00[/TD]
[TD]$112.20[/TD]
[TD]18.00[/TD]
[TD]$91.80[/TD]
[TD]30.00[/TD]
[TD]$333.60[/TD]
[TD]35.00[/TD]
[TD]$286.14[/TD]
[/TR]
[TR]
[TD]HV05[/TD]
[TD]27.00[/TD]
[TD]$156.30[/TD]
[TD]16.00[/TD]
[TD]$155.87[/TD]
[TD]25.00[/TD]
[TD]$243.55[/TD]
[TD]23.00[/TD]
[TD]$258.64[/TD]
[TD]20.00[/TD]
[TD]$102.00[/TD]
[TD]16.00[/TD]
[TD]$81.60[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD]29.00[/TD]
[TD]$237.09[/TD]
[/TR]
[TR]
[TD]HV06[/TD]
[TD]26.00[/TD]
[TD]$150.51[/TD]
[TD]13.00[/TD]
[TD]$126.65[/TD]
[TD]10.00[/TD]
[TD]$97.42[/TD]
[TD]20.00[/TD]
[TD]$224.90[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD]16.00[/TD]
[TD]$81.60[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD]27.00[/TD]
[TD]$220.74[/TD]
[/TR]
[TR]
[TD]HV07[/TD]
[TD]22.00[/TD]
[TD]$127.36[/TD]
[TD]16.00[/TD]
[TD]$155.87[/TD]
[TD]19.00[/TD]
[TD]$185.10[/TD]
[TD]2.00[/TD]
[TD]$22.49[/TD]
[TD]27.00[/TD]
[TD]$137.70[/TD]
[TD]24.00[/TD]
[TD]$122.40[/TD]
[TD]17.00[/TD]
[TD]$189.04[/TD]
[TD]14.00[/TD]
[TD]$114.46[/TD]
[/TR]
[TR]
[TD]HV08[/TD]
[TD]12.00[/TD]
[TD]$69.47[/TD]
[TD]8.00[/TD]
[TD]$77.94[/TD]
[TD]4.00[/TD]
[TD]$38.97[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD]20.00[/TD]
[TD]$102.00[/TD]
[TD]10.00[/TD]
[TD]$111.20[/TD]
[TD]9.00[/TD]
[TD]$73.58[/TD]
[/TR]
[TR]
[TD]HV09[/TD]
[TD]25.00[/TD]
[TD]$144.73[/TD]
[TD]12.00[/TD]
[TD]$116.90[/TD]
[TD]23.00[/TD]
[TD]$224.07[/TD]
[TD]0.00[/TD]
[TD]$0.00[/TD]
[TD]26.00[/TD]
[TD]$132.60[/TD]
[TD]24.00[/TD]
[TD]$122.40[/TD]
[TD]28.00[/TD]
[TD]$311.36[/TD]
[TD]12.00[/TD]
[TD]$98.10[/TD]
[/TR]
</tbody><colgroup><col><col><col><col><col><col span="12"></colgroup>[/TABLE]


Summary:
[TABLE="width: 189"]
<tbody>[TR]
[TD][/TD]
[TD="align: right"]Sep-17[/TD]
[/TR]
[TR]
[TD]PARTs[/TD]
[TD]Tatal Quantity[/TD]
[/TR]
[TR]
[TD]JC01[/TD]
[TD]29.00[/TD]
[/TR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.00[/TD]
[/TR]
[TR]
[TD]HV08[/TD]
[TD]9.00[/TD]
[/TR]
[TR]
[TD]HV09[/TD]
[TD]12.00[/TD]
[/TR]
</tbody><colgroup><col><col></colgroup>[/TABLE]

Looking forward to hear the good news soon. 

Thanks in advance for the helps.

 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try this:
Code:
Sub Consolidate_Data()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim Lastrowa As Long
Dim LastColumn As Long
    For i = 1 To Sheets.Count
        If Sheets(i).Name <> "Summary" Then
            LastColumn = Sheets(i).Cells(2, Columns.Count).End(xlToLeft).Column - 1
            Sheets("Summary").Range("A2").Value = Sheets(i).Range("A2").Value
            Lastrowa = Sheets(i).Cells(Rows.Count, "A").End(xlUp).Row
            Lastrow = Sheets("Summary").Cells(Rows.Count, "A").End(xlUp).Row + 1
            With Sheets(i)
                Sheets("Summary").Range("B1").Value = Sheets(i).Cells(1, LastColumn).Value
                Sheets("Summary").Range("B2").Value = Sheets(i).Cells(2, LastColumn).Value
                .Range("A3:A" & Lastrowa).Copy Sheets("Summary").Range("A" & Lastrow)
                .Range(.Cells(3, LastColumn), .Cells(Lastrowa, LastColumn)).Copy Sheets("Summary").Range("B" & Lastrow)
            End With
        
        End If
    Next
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,128
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