Hi, I'm a beginner at Excel, so please bear with me.
I have a workbook with multiple worksheets. Each worksheet is a set o data from a certain year. I want to create a macro that automatically copies the data from these worksheets into a master worksheet that can easily be used to make a pivot table. How can I do this? (I included a sample workbook in the attachments.)
Last edited by Michael.H.; 06-23-2009 at 08:34 PM.
If every sheet has the exact same column headers, all the data is already in the correct place and you just want "Summary" report created, then this basic macro does that:
Run the SummaryReport macro (press Alt-F8)Option Explicit Public Function SheetExists(SName As String, Optional ByVal Wb As Workbook) As Boolean 'Chip Pearson On Error Resume Next If Wb Is Nothing Then Set Wb = ThisWorkbook SheetExists = CBool(Len(Wb.Sheets(SName).Name)) End Function Sub SummaryReport() 'JBeaucaire (6/21/2009) 'Copy rows of data from multiple sheets to one matching one ID # Dim ws As Worksheet, LR As Long, NR As Long 'Setup If SheetExists("Report") Then Sheets("Report").Range("A2:Z" & Rows.Count).ClearContents Else Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Report" Sheets(1).Rows(1).EntireRow.Copy Sheets("Report").Range("A1") End If NR = 2 'Copy data to Report For Each ws In Worksheets If ws.Name <> "Report" Then ws.Activate LR = Range("A" & Rows.Count).End(xlUp).Row Range("A2:Z" & LR).Copy Sheets("Report").Range("A" & NR) NR = NR + LR - 1 End If Next ws End Sub
If you run it successively, it erases the existing report and creates a new one.
If you don't want the old report erased but want new data appended to the bottom of the existing report, comment out or erase the "optional" line of code in the macro.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
Thanks a million! This is great!
If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].
(Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks