Copying All Worksheets after Sheet4 (position) into a new .xlsx workbook

jconkl02

Board Regular
Joined
May 25, 2016
Messages
55
I have a workbook that will have a dozen or so sheets that will vary in name on a regular basis. I want to be able to copy all sheets after the fourth sheet into a new .xlsx workbook.

I have looked for a solution, but all I find is
Code:
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Copy

But the names of the sheets will be changing, so I need a solution that uses some form of "To Sheets.Count ".

Any ideas?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
How about
Code:
Sub jconkl02()
   Dim ary As Variant
   Dim i As Long
   ReDim ary(1 To Worksheets.Count - 4)
   For i = 5 To Worksheets.Count
      ary(i - 4) = Sheets(i).Name
   Next i
   Sheets(ary).Copy
End Sub
 
Upvote 0
Solution
Fluff,

That was perfect! I miscounted the number of sheets I wanted to exclude, but I just reduced all of the numbers in the macro by 1 and it worked perfect.

Thanks again.
jason

How about
Code:
Sub jconkl02()
   Dim ary As Variant
   Dim i As Long
   ReDim ary(1 To Worksheets.Count - 4)
   For i = 5 To Worksheets.Count
      ary(i - 4) = Sheets(i).Name
   Next i
   Sheets(ary).Copy
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

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