PDA

View Full Version : [SOLVED:] automatically consolidate data from different sheets to 1 combined sheet



jdmelgar
09-18-2017, 05:58 AM
Hi,

Need help to get sheets 2 to 4 (named Sample1, Sample2, Sample3) data to one consolidated sheet (sheet 1), sheet named Combined.

I have attached the working file for your reference.

Thank you in advance.

Kind regards,
James

mdmackillop
09-19-2017, 02:21 AM
Sub Test()
Set ws = Sheets("Combined")
For Each sh In Sheets
If sh.Name <> "Combined" Then
Set tgt = ws.Cells(Rows.Count, 1).End(xlUp)(2)
sh.UsedRange.Offset(1).Copy tgt
End If
Next
End Sub

jdmelgar
09-19-2017, 03:01 AM
Wow! Thank you.

A bit cheeky but can you add something that everytime i run the macro, it will delete the previous data and just retain the latest run. I tried to run the macro twice and it added the data twice.

Thank you in advance!

mdmackillop
09-19-2017, 03:17 AM
Sub Test()
Set ws = Sheets("Combined")
ws.UsedRange.Offset(1).ClearContents

For Each sh In Sheets
If sh.Name <> "Combined" Then
Set tgt = ws.Cells(Rows.Count, 1).End(xlUp)(2)
sh.UsedRange.Offset(1).Copy tgt
End If
Next
End Sub

jdmelgar
09-19-2017, 06:46 AM
Amazing! Thank you so much for this. Appreciate it.