Consolidating data using VBA, end with set Layout

JaapHeijndemans

New Member
Joined
Feb 15, 2018
Messages
2
Hello,

Im working on a large file with around 22 tabs and I want to use VBA to consolidate all this data in a master file. I have the following code that I am using right now on my test file that is doing a perfect job of consolidating all the information:

Sub CombineWorksheets()
'Declare the variables
Dim wksCombined As Worksheet
Dim wks As Worksheet
Dim CalcMode As Long
Dim LastRow As Long

'Change the settings for Calculation and ScreenUpdating
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

'Delete the Total Overview WorkSheet if it exists
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Sheets("Total Overview").Delete
Application.DisplayAlerts = True

'Add a new worksheet before the first worksheet in the active workbook
Set wksCombined = Worksheets.Add

'Name the new worksheet
wksCombined.Name = "Total Overview"

'Set up the headers for the new worksheet
With Worksheets(3)
.Range("A1:V1").Copy Destination:=wksCombined.Range("A1")
End With

'Loop through each worksheet within the active workbook
For Each wks In ActiveWorkbook.Worksheets
'Skip the new worksheet
If wks.Name <> "Total Overview" Then
With wks
'Find the last used row in Column A
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
'Copy the data from the current worksheet to the first available row of the new worksheet starting at Column A
.Range("A2", .Cells(LastRow, "V")).Copy Destination:=wksCombined.Cells(wksCombined.Cells.Rows.Count, "A").End(xlUp).Offset(1)
End With
End If
Next wks

'Restore the settings for Calculation and ScreenUpdating
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

'Display a message indicating that the macro has finished
MsgBox "Completed...", vbInformation

End Sub


The problem that I run into is that I need to update this quite often and everytime I run the script the layout resets. My questions is if its possible to run a line in the script, that will allow me to change the layout of the final page without needing to doing it manually after I run the script.

Anyone that could help me?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Oh god, thank you for the response Pat, I totally forgot about this.
I recorded the macros and after some adjusting I ran the script and it works perfectly.

Thanks at least for opening my eyes for this option hehe.
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,994
Members
452,542
Latest member
Bricklin

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