Sub Combine()
Dim J As Integer
On Error Resume Next
Sheets(1).Select
Worksheets.Add
Sheets(1).name = "Combined"
Sheets(2).Activate
Range("A1").EntireRow.Select
Selection.Copy Destination:=Sheets(1).Range("A1")
For J = 2 To Sheets.Count
Sheets(J).Activate
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Copy
Sheets(1).Range("A65536").End(xlUp)(2).PasteSpecial xlPasteValues
Next
End Sub
Does this work? If so, we can get working on removing .select
to make this a little bit more "tight". I already did it on the .Copy
line (can you see what I did?)
Edit: This almost gets there - I think you'll hit an issue on the pasting part, but I can fix that. Just tell me, in your original code, what is the CurrentRegion
that you're selecting? What's trying to be copy/pasted?
Edit 2: Okay, I think I've got it finally. The issue is your using Sheets(1)
, Sheets(2)
. I don't know how your document is, but the following works with these assumptions: You have the "unchanging" sheet active (this is the sheet with your magical formulas). Just have this active and run the macro below.
Sub Combine()
Dim J As Integer, noRows As Integer
Dim ws1 As Worksheet, ws2 As Worksheet, magicWS As Worksheet
' Note, you need to have the worksheet where you do all of your formulas open and be the active sheet.
Set magicWS = ActiveSheet
Set ws1 = Sheets.Add(after:=magicWS)
ws1.Name = "Combined"
On Error Resume Next
'Now, I assume that your main (unchanging) worksheet is the FAR LEFT most
'Then, the second worksheet is the new "Combined". If you look along the bottom, every worksheet RIGHT of "Combined" will need
'to be added to this WS.
'First, let's get the headers from the third sheet:
ws1.Cells.Rows(1).Value = Sheets(3).Cells.Rows(1).Value
'Now, let's add the data to "Combined"!
For J = 3 To Sheets.Count
noRows = Sheets(J).Range("A1").CurrentRegion.Rows.Count
Sheets(J).Range("A1").CurrentRegion.Offset(1, 0).Resize(noRows - 1).Copy
ws1.Range("A65536").End(xlUp)(2).PasteSpecial xlPasteValues
Next J
Application.CutCopyMode = False
End Sub