I am writing a macro to copy a sheet and add it to a specific location within the workbook. This macro will be used for workbooks with different numbers of sheets, so I want it to continue to copy and add worksheets until there are no more sheets left.
Sub Macro()
Dim x As Integer
For x = 3 To Sheets.Count Step 3
Sheets(x).Select
Sheets(x).Copy Before:=Sheets(x + 3)
A bunch more code...
Next
The macro obviously runs from 3 to the total number of worksheets, but because the total number of worksheets changes after each step (due to copying/adding a worksheet), the macro stops before it gets to the end of the workbook (I'm guessing because it stops running when the counter reaches the start value of sheets.count). Any suggestions on how to make the macro continue through to the end? This is my first experience writing code so please be gentle :)
while x<nrOfSheets
. – surfmuggle