Consolidating reports

pliant

Board Regular
Joined
Jan 8, 2003
Messages
238
I have reports done in Excel sent to be by various locations every month. I'd like to combine all these reports into one large report. Is there an easy way to automate this so that I can just click a button each month for this to happen instead of cut and pasting each one into the large report?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Can you provide some more information? For example:


  • What is the layout of the data? What columns are you using? Does each file have headers?

    How many files are you consolidating? Is it a constant number of files or do you require a dynamic solution?
 
Upvote 0
There will be around 12 reports but it could vary. There are 11 columns in the report and they each have header information.
 
Upvote 0
Try this code (not tested) and let me know if it works okay for you.

Code:
Sub CombineFiles()
' Written by Barrie Davidson
Dim Rollup_File_Name As String
Dim File_Names As Variant
Dim File_count As Integer
Dim Active_File_Name As String
Dim Counter As Integer
Dim File_Save_Name As Variant
    
File_Names = Application.GetOpenFilename _
    ("Excel Files (*.xl*), *.xl*", , , , True)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
File_count = UBound(File_Names)
Counter = 1
Do Until Counter > File_count
    Workbooks.Add
    Rollup_File_Name = ActiveWorkbook.Name
    Active_File_Name = File_Names(Counter)
    Workbooks.Open FileName:=Active_File_Name
    Active_File_Name = ActiveWorkbook.Name
    If Counter = 1 Then
        Range("A1:K" & Range("A65536").End(xlUp).Row).Copy _
            Destination:=Workbooks(Rollup_File_Name). _
            Sheets(1).Range("A1")
    Else
        Range("A2:K" & Range("A65536").End(xlUp).Row).Copy _
            Destination:=Workbooks(Rollup_File_Name). _
            Sheets(1).Range("A65536").End(xlUp).Offset(1, 0)
    End If
    Workbooks(Active_File_Name).Close False
    Counter = Counter + 1
Loop
GetSaveName:
File_Save_Name = Application.GetSaveAsFilename
Select Case File_Save_Name.Value
    Case Is = False
        MsgBox ("Please enter a file name to save the file")
        GoTo GetSaveName
    Case Is = ""
        MsgBox ("Please enter a file name to save the file")
        GoTo GetSaveName
    Case Else
End Select
Workbooks(Rollup_File_Name).SaveAs FileName:=File_Save_Name
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

Regards,
 
Upvote 0
Barrie

Do I understand this correctly?

In summary, I think this code will take all the currently open files and copy and paste them into a master file and then prompt the user to enter a file name for the master.

thanks
 
Upvote 0
geolefty said:
Barrie

Do I understand this correctly?

In summary, I think this code will take all the currently open files and copy and paste them into a master file and then prompt the user to enter a file name for the master.

thanks

Close, it will prompt you to select files that you want to combine (via a file open message box), consolidate those files in a new file, and then prompt you for the file save name for the new file.

Regards,
 
Upvote 0
It doesn't seem to be working...nothing is being copied over into the open workbook and i'm getting and error "Object Required" when it tries to save at the end
 
Upvote 0
Okay, I tested the code and found the errors. Try this instead

Code:
Sub CombineFiles()
' Written by Barrie Davidson
Dim Rollup_File_Name As String
Dim File_Names As Variant
Dim File_count As Integer
Dim Active_File_Name As String
Dim Counter As Integer
Dim File_Save_Name As Variant
    
File_Names = Application.GetOpenFilename _
    ("Excel Files (*.xl*), *.xl*", , , , True)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
File_count = UBound(File_Names)
Counter = 1
Workbooks.Add
Rollup_File_Name = ActiveWorkbook.Name
Do Until Counter > File_count
    Active_File_Name = File_Names(Counter)
    Workbooks.Open FileName:=Active_File_Name
    Active_File_Name = ActiveWorkbook.Name
    If Counter = 1 Then
        Range("A1:K" & Range("A65536").End(xlUp).Row).Copy _
            Destination:=Workbooks(Rollup_File_Name). _
            Sheets(1).Range("A1")
    Else
        Range("A2:K" & Range("A65536").End(xlUp).Row).Copy _
            Destination:=Workbooks(Rollup_File_Name). _
            Sheets(1).Range("A65536").End(xlUp).Offset(1, 0)
    End If
    Workbooks(Active_File_Name).Close False
    Counter = Counter + 1
Loop
GetSaveName:
File_Save_Name = Application.GetSaveAsFilename(, _
    "Excel Files (*.xls), *.xls")
Select Case File_Save_Name
    Case Is = False
        MsgBox ("Please enter a file name to save the file")
        GoTo GetSaveName
    Case Is = ""
        MsgBox ("Please enter a file name to save the file")
        GoTo GetSaveName
    Case Else
End Select
Workbooks(Rollup_File_Name).SaveAs FileName:=File_Save_Name
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

Let me know if I've got it now.
 
Upvote 0
still nothing is being copied over and now i'm getting a "400" error when it come to saving...
 
Upvote 0
pliant said:
still nothing is being copied over and now i'm getting a "400" error when it come to saving...

What exactly is your error message? What part of the code is getting the error? I tested the new code and it worked fine for me.
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,047
Members
449,206
Latest member
Healthydogs

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