Excel - Copy data from a range of sheets to a master sheet
On January 19,2023 by Tom RoutleyIssue
I need to develop a macro that will collect data from a range of sheets in a workbook.
The macro needs to:
Copy data for a range of sheets after the sheet called "All Deadlines" and before the sheet called "Template". So all sheets falling between sheet "All Deadlines" and sheet "Template".
I need all rows which have data in them from Row 14 onwards for sheets in the range, but for the macro only to copy the rows which include data
Once launch, the macro should copy the data to the sheet called "All Deadlines", pasting to Row 3 for the first time and pasting the data from each subsequent sheet below the last previous entry.
When run, the macro should delete all data from Row 3 and below on the sheet "All Deadlines" (data collected from previous runs of the macro).
Solution
Adjust the below code to fit your requirements:
Sub MoveData() Dim ws As Worksheet Dim lRow, dRow As Integer Sheets("All Deadlines").Rows("3:" & Range("A" & Rows.Count).End(xlUp).Row).ClearContents For Each ws In Sheets If ws.Name = "Create New Project" _ Or ws.Name = "Project Dashboard" _ Or ws.Name = "All Deadlines" _ Or ws.Name = "Template" Then GoTo Nextws dRow = Sheets("All Deadlines").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Row lRow = Sheets(ws.Name).Range("A" & Rows.Count).End(xlUp).Row Sheets(ws.Name).Rows("14:" & lRow).Copy Sheets("All Deadlines").Range("A" & dRow) Nextws: Next ws End Sub
Thanks to TrowaD for this tip.
Article Recommendations
Latest articles
Popular Articles
Archives
- November 2024
- October 2024
- September 2024
- August 2024
- July 2024
- June 2024
- May 2024
- April 2024
- March 2024
- February 2024
- January 2024
- December 2023
- November 2023
- October 2023
- September 2023
- August 2023
- July 2023
- June 2023
- May 2023
- April 2023
- March 2023
- February 2023
- January 2023
- December 2022
- November 2022
- October 2022
- September 2022
- August 2022
- July 2022
- June 2022
- May 2022
- April 2022
- March 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
- January 2021
Leave a Reply