Hello all,
I have a workbook with around 500 sheets. All sheets look the same, same number of columns, etc.
I need a vba to copy the content from all sheets into a new one and paste them one after another.
Here is what i managed to do until now...
The problem that i have right now, is that if the Sheet "Combined" already exists, i recieve runtime error 1004 (the name is already taken).
Regarding the fact that i will execute this code a few times everyday, this is a dealbreaker...
Could you please help me with a solution? How can i delete the sheet "Combined" befor executing the rest of the code?
Thank you in advance.
I have a workbook with around 500 sheets. All sheets look the same, same number of columns, etc.
I need a vba to copy the content from all sheets into a new one and paste them one after another.
Here is what i managed to do until now...
Code:
Sub Combine()
Worksheets.Add
Sheets(1).Name = "Combined"
Sheets(1).Range("A1").EntireRow.Value = Sheets(2).Range("A1").EntireRow.Value 'not most effecient, but will do for this
Dim J As Integer
For J = 2 To Sheets.Count ' from sheet 2 to last sheet
With Sheets(J)
.Range(.Cells(2, 1), .Cells(.Range("A" & .Rows.Count).End(xlUp).Row, .Cells(2, .Columns.Count).End(xlToLeft).Column)).Copy _
Sheets(1).Range("A" & Rows.Count).End(xlUp).Offset(2)
End With
Next
End Sub
The problem that i have right now, is that if the Sheet "Combined" already exists, i recieve runtime error 1004 (the name is already taken).
Regarding the fact that i will execute this code a few times everyday, this is a dealbreaker...
Could you please help me with a solution? How can i delete the sheet "Combined" befor executing the rest of the code?
Thank you in advance.