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: 

Sheet1May-17Jun-17Jul-17Aug-17Sep-17
PARTsTatal QuantitypriceTatal QuantitypriceTatal QuantitypriceTatal QuantitypriceTatal Quantityprice
JC01160.15$1,263.58280.00$3,514.0032.00$401.6016.00$126.2429.00$363.95
JC0271.00$560.19329.98$4,141.2528.00$351.4018.00$142.0220.50$257.28
JC030.00$0.0060.00$753.0031.00$389.050.00$0.003.00$37.65
JC040.00$0.0018.00$225.9070.00$878.5028.00$220.928.00$100.40
JC0520.00$157.80112.00$1,405.6012.00$150.606.00$47.342.00$25.10
JC0611.00$86.79 $0.0017.00$213.350.00$0.000.00$0.00
JC0755.00$433.95 $0.0020.00$251.000.00$0.002.00$25.10
JC080.00$0.00 $0.0021.00$263.550.00$0.0010.00$125.50

<tbody>
</tbody><colgroup><col><col><col><col><col><col span="6"></colgroup>


Sheet2May-17Jun-17Jul-17Aug-17Sep-17
PARTsTatal QuantitypriceTatal QuantitypriceTatal QuantitypriceTatal QuantitypriceTatal Quantityprice
99D0133.00$214.5030.00$267.0034.00$302.6038.00$247.007.00$45.50
99D0231.00$201.5030.00$267.0032.00$284.802.00$13.007.00$45.50
99D0332.00$208.0027.00$240.3035.00$311.505.00$32.5034.00$221.00
99D0433.00$214.5029.00$258.1023.00$204.7013.00$84.5032.00$208.00
99D0532.00$208.0029.00$258.1073.00$649.7015.00$97.5036.00$234.00
99D0632.00$208.0029.00$258.105.00$44.508.00$52.0042.00$273.00
99D0736.00$234.0030.00$267.0063.00$560.706.00$39.005.00$32.50
99D0833.00$214.5030.00$267.0048.00$427.206.00$39.002.00$13.00
99D0918.00$117.0030.00$267.0075.00$667.5053.00$344.5034.00$221.00
99D1039.00$253.5029.00$258.1050.00$445.0047.00$305.5034.00$221.00
99D1132.00$208.0030.00$267.008.00$71.208.00$52.0045.00$292.50
99D1239.00$253.5035.00$311.509.00$80.106.00$39.006.00$39.00
99D1322.00$143.0022.00$195.8017.00$151.3010.00$65.0041.00$266.50
99D1425.00$162.5029.00$258.1050.00$445.0052.00$338.008.00$52.00

<tbody>
</tbody><colgroup><col><col><col><col><col><col span="6"></colgroup>

Sheet3Feb-17Mar-17Apr-17May-17Jun-17Jul-17Aug-17Sep-17
PARTsTatal QuantitypriceTatal QuantitypriceTatal QuantitypriceTatal QuantitypriceTatal QuantitypriceTatal QuantitypriceTatal QuantitypriceTatal Quantityprice
HV0130.00$173.676.00$58.4523.00$224.0728.00$314.8636.00$183.6015.00$76.5027.00$300.2424.00$196.21
HV0228.00$162.0927.00$263.035.00$48.7125.00$281.130.00$0.0032.00$163.2027.00$300.2426.00$212.56
HV0341.00$237.3560.00$584.5228.00$272.7814.00$157.4335.00$178.5032.00$163.2019.00$211.2830.00$245.26
HV0412.00$69.4723.00$224.072.00$19.4825.00$281.1322.00$112.2018.00$91.8030.00$333.6035.00$286.14
HV0527.00$156.3016.00$155.8725.00$243.5523.00$258.6420.00$102.0016.00$81.600.00$0.0029.00$237.09
HV0626.00$150.5113.00$126.6510.00$97.4220.00$224.900.00$0.0016.00$81.600.00$0.0027.00$220.74
HV0722.00$127.3616.00$155.8719.00$185.102.00$22.4927.00$137.7024.00$122.4017.00$189.0414.00$114.46
HV0812.00$69.478.00$77.944.00$38.970.00$0.000.00$0.0020.00$102.0010.00$111.209.00$73.58
HV0925.00$144.7312.00$116.9023.00$224.070.00$0.0026.00$132.6024.00$122.4028.00$311.3612.00$98.10

<tbody>
</tbody><colgroup><col><col><col><col><col><col span="12"></colgroup>


Summary:
Sep-17
PARTsTatal Quantity
JC0129.00
JC0220.50
JC033.00
JC048.00
JC052.00
JC060.00
JC072.00
JC0810.00
99D017.00
99D027.00
99D0334.00
99D0432.00
99D0536.00
99D0642.00
99D075.00
99D082.00
99D0934.00
99D1034.00
99D1145.00
99D126.00
99D1341.00
99D148.00
HV0124.00
HV0226.00
HV0330.00
HV0435.00
HV0529.00
HV0627.00
HV0714.00
HV089.00
HV0912.00

<tbody>
</tbody><colgroup><col><col></colgroup>

Looking forward to hear the good news soon. 

Thanks in advance for the helps.

 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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