I have a workbook with 4 worksheets.
Worksheet 1 feeds worksheets 2 and 4 with some manual inputs as well.
Worksheet 3 feeds from worksheet 2
I want my users to be able to create duplicate sets of worksheets 2 & 3 (whereas the duplicate 2 worksheet still feeds from worksheet 1, and the duplicate 3 worksheet feeds from the duplicate 2 worksheet and not the original 2 worksheet).
I found that if I select both worksheets and copy them together that this does exactly what I want. Writing the code for this was easy until people started changing the names of the worksheets. So I switched to using their code names instead. That way it didn’t matter if they switched the name.
It starts to get more complicated when I want them to be able not only make duplicate copies of the original sheets 2 & 3, but be able to make copies of the new duplicate sheets 2 & 3 as well. I don’t know what those new sheets code names will be.
My question is, is there a way to write the code so that it will select the active sheet, determine its code name and then select both the active sheet and the sheet with the next numerical code name? Since the macro button is set on sheet 2 (and therefore any of its duplicates as well), any time a copy is made via the macro, my duplicate copies of page 2 & 3 always have sequential code names. If it helps, here is the original code written for what I said I was able to accomplish so far.
test1 Macro
'
'
Sheets(Array(Sheet2.Name, Sheet3.Name)).Select
Sheets(Sheet2.Name).Activate
Sheets(Array(Sheet2.Name, Sheet3.Name)).Copy Before:=Sheets(4)
Range("G16").Select
End Sub
So to rephrase, I want to copy the active worksheet and the worksheet with the next sequentially numbered code name despite whether it has been moved around in the workbook or renamed.