[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to merge multiple spreadsheets in Excel 2003

Posted on 2011-10-28
11
Medium Priority
?
302 Views
Last Modified: 2012-05-12
Hi Experts. I have collected storage performance data for 30 MS Exchange servers. The higher ups want to see it in a spreadsheet. How do I merge these documents into a single spreadsheet? Thank you!
0
Comment
Question by:Rhiaanon44
  • 6
  • 4
11 Comments
 
LVL 26

Expert Comment

by:redmondb
ID: 37048348
Hi, Rhiaanon44.

Please see the code below. A few notes...
(1) Set the XHEADER_ROWS constant to the no. of rows in the header (so it isn't duplicated from the second and subsequent sheets). You can set this to 0 if you want all rows from all sheets.
(2) The macro unprotects, unfilters, unhides rows and columns the two sheets.
(3) Because formulas may cause problems in the new "Merge" sheet, the macro pastes values only. Obviously it can be changed if you want formatting also or formulas instead.
(4) The macro doesn't bother checking if "Merge" already exists - instead it fails ungracefully.
(5) The results are slightly untidy if the second (or subsequent) sheet only has the header rows (i.e. no data).
Option Explicit

Const XHEADER_ROWS = 1

Sub Merge_Multiple_Sheets_Paste_Values()

Dim xNewSheet As Worksheet
Dim xOldSheet As Worksheet
Dim xSheet As Worksheet
Dim xResponse As Long
Dim xhold As String
Dim xLast_Row As Long
Dim xStart_Row As Long
Dim xFirst As Boolean

With Application
    .EnableEvents = False
    .ScreenUpdating = False
    .Calculation = xlManual
End With

    Set xNewSheet = Sheets.Add
    xNewSheet.Name = "Merge"
    xFirst = True
    
    For Each xOldSheet In ActiveWorkbook.Sheets '(Array("Sheet1", "Sheet2"))
    
        If Not xOldSheet.Name = "Merge" Then
            
            If xOldSheet.ProtectContents Then xOldSheet.Unprotect ' If there's a password then add it as a string here.
            If xOldSheet.FilterMode Then xOldSheet.ShowAllData
            
            xOldSheet.Cells.EntireColumn.Hidden = False
            xOldSheet.Cells.EntireRow.Hidden = False
            
            xLast_Row = Sheets("Merge").Range("A1").SpecialCells(xlLastCell).ROW
            If xFirst Then
                xStart_Row = 1
                xFirst = False
            Else
                '''If xLast_Row = XHEADER_ROWS Then Exit For
                xStart_Row = XHEADER_ROWS + 1
                xLast_Row = xLast_Row + 1
            End If
            
            xOldSheet.Range("A" & xStart_Row & ":" & xOldSheet.Range("A1").SpecialCells(xlLastCell).Address).Copy
            Sheets("Merge").Cells(xLast_Row, 1).PasteSpecial (xlPasteValues)
        
        End If
        
    Next
    
    Sheets("Merge").Range("A1").Activate
    
With Application
    .EnableEvents = True
    .ScreenUpdating = True
    .Calculation = xlAutomatic
End With

End Sub

Open in new window

Regards,
Brian.
0
 
LVL 26

Expert Comment

by:redmondb
ID: 37048352
Rhiaanon44,

Ehm, I should probably have said that I am assuming the data is already in 30 sheets in the workbook. If any of this is incorrect, please let me know the details!

Regards,
Brian.
0
 

Author Comment

by:Rhiaanon44
ID: 37048518
Hi Redmonb.All 30 are in a spreadsheet. However, I should have said I am novice with excel. This work was given to me because I am the new guy.  =)  
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 26

Expert Comment

by:redmondb
ID: 37048548
Rhiaanon44,

We were all there once, but at least you've found your way here!

What we're going to do isn't going to be too complicated - as long as I explain properly, so please bear with me. :)

OK, some questions,...
(1) Which version of Excel are you using?
(2) If the file isn't too big, can you post it here? (If the data is confidential (or you're just not sure) then the correct answer is "No".) If not, can you tell me
(a) what kind of file it is,
(b) on average, roughly how many rows per sheet,
(c)  Are the headers for each sheet identical?
(3) Have you ever looked at a macro within Excel?

Thanks,
Brian.
0
 

Author Comment

by:Rhiaanon44
ID: 37048579
There are 37 server names but I just put several bogus ones there. Also, there are 6 columns more of these kind of data. All 30 sheets have the same data requested for the 37 servers.                                                            
 Excel.xlsx
0
 
LVL 26

Accepted Solution

by:
redmondb earned 1600 total points
ID: 37048620
John,

Excellent, thanks.

In the attached file, I added a new sheet called Fred and copied into it the data from the original sheet (changing most of the numbers). I then copied the macro into the file, changed the XHEADER_ROWS constant to 0 and ran the macro.

The result is in the "Merge" sheet. Have a look and see whether it's acceptable for you.

BTW, I'll be finishing here for the night in the next 15 minutes or so. I'll be back again in about 6 or 7 hours. How much longer will you be here for and when will you be back again?

Thanks,
Brian.
Excel-V2.xlsm
0
 
LVL 26

Expert Comment

by:redmondb
ID: 37048638
John?! Sorry, Rhiaanon44, I mixed up two posts. Definitely time for bed!
0
 

Author Comment

by:Rhiaanon44
ID: 37048657
Thanks Redmonb. I will be back on in the AM. I am looking at your work. Awesome! Thanks!
0
 
LVL 34

Assisted Solution

by:Rob Henson
Rob Henson earned 400 total points
ID: 37063227
Without wishing to further complicate Brian's work, can I suggest a Pivot Table from multiple sources as another option. If the layouts of the 37 separate sheets are the same, the pivot table will consolidate all sheets into one sheet and will enable grouping etc.

There are lots of Pivot Table tutorials dotted around the net that should give enough detail of how to do this.

Thanks
Rob H
0
 

Author Closing Comment

by:Rhiaanon44
ID: 37063860
Thank you both! I cannot thank you enough!!!
0
 
LVL 26

Expert Comment

by:redmondb
ID: 37064020
Thanks, Rhiaanon44. Good suggestion Rob.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question