Combining multiple sheets into one

ldasil

New Member
Joined
Dec 12, 2013
Messages
2
I am downloading a report into excel on a weekly basis. It downloads into about 50 sheets in one workbook and I cannot change that so I am looking for a macro that will combine them into one long sheet. I would like it to create a new sheet and copy/paste each row (all columns or A-Q if it matters) from sheet 1, then on the next line start with row 1 from sheet 2, and so on. Each sheet has a different number of rows, but the last row on each sheet will always be the last row that has data in column G. The number of sheets could also change from week to week. I tried revising a code found in an old thread but I don’t know how to tell it to copy from row 1 down to the last row w/ data in “G”. Thanks for any help you can provide!


Option Explicit

Sub CombineWorksheets()

'Declare the variables
Dim wksCombined As Worksheet
Dim wks As Worksheet
Dim CalcMode As Long
Dim LastRow As Long

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

'Name the new worksheet
wksCombined.Name = "Combined"

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

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

End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Thanks, that is a helpful link. However, using the example I'm getting "Sub or Function not defined" for "LastRow" under find last row with data. Is that something I'm supposed to replace?
 
Upvote 0

Forum statistics

Threads
1,216,471
Messages
6,130,822
Members
449,595
Latest member
jhester2010

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