Hello
I have created a workbook that has 47 sheets ("master worksheets") all of which are hidden except for Sheet 1 - the Index. I have written some code to create a copy of a sheet when the corresponding button is pressed. It works fine except for the fact that the copies created are no longer in the same order as the master worksheets (something to do with the index order of the worksheets because some are hidden etc.). I tried to create a workaround this by writing a macro that would unhide all the master worksheets each time before copying the worksheet needed so that they copies end up in the same order as the masters (copy function used is copy after the worksheet being copied).
The code I have written to unhide the hidden worksheets is as follows:
Now I can't seem to work out what code to include to get the i + 1 to stop after Sheet 47 (the last of the "master worksheets") when unhiding the worksheets. After I work out how to do this, then I'm assuming I'd be able to use something similar to hide the same master worksheets once the copy has been created and placed in the right spot.
If anyone can help me with this, it'll be greatly appreciated. If there is an easier way to do this, please share!
If anything I've said is unclear please let me know.
Thanks in anticipation.
I have created a workbook that has 47 sheets ("master worksheets") all of which are hidden except for Sheet 1 - the Index. I have written some code to create a copy of a sheet when the corresponding button is pressed. It works fine except for the fact that the copies created are no longer in the same order as the master worksheets (something to do with the index order of the worksheets because some are hidden etc.). I tried to create a workaround this by writing a macro that would unhide all the master worksheets each time before copying the worksheet needed so that they copies end up in the same order as the masters (copy function used is copy after the worksheet being copied).
The code I have written to unhide the hidden worksheets is as follows:
VBA Code:
Sub BatchChange_Unhide()
' Unhides all Worksheets in the Active Workbook
Dim i As Integer, ws As Worksheet
i = 0
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Sheets
i = i + 1
On Error Resume Next
ws.Visible = True
On Error GoTo 0
Next ws
Sheet1.Activate
Application.ScreenUpdating = True
End Sub
Now I can't seem to work out what code to include to get the i + 1 to stop after Sheet 47 (the last of the "master worksheets") when unhiding the worksheets. After I work out how to do this, then I'm assuming I'd be able to use something similar to hide the same master worksheets once the copy has been created and placed in the right spot.
If anyone can help me with this, it'll be greatly appreciated. If there is an easier way to do this, please share!

If anything I've said is unclear please let me know.
Thanks in anticipation.