MPW
Well-known Member
- Joined
- Oct 7, 2009
- Messages
- 571
- Office Version
- 365
- Platform
- Windows
Hi All,
I am writing some VBA lines that exist in one workbook into another one.
To do this I first need to add and name the sheet names that exist in #1wkbk into #2wkbk. This I can do by using this:
This will create new sheets in the new wkbk with the same names. My problem comes in with the sheet number.
becomes
This causes problems when transferring the lines of code. What I want to do is change the number of the sheet like I do when I name it using the routine above. That would also help me clean up the code by eliminating the "if" condition all together.
Thanks
I am writing some VBA lines that exist in one workbook into another one.
To do this I first need to add and name the sheet names that exist in #1wkbk into #2wkbk. This I can do by using this:
Code:
For Each ww In oldwkbk.Worksheets
WSName = ww.Name
If oldwkbk.Sheets(1).Name = WSName Then
newwkbk.Sheets(1).Name = WSName
ElseIf oldwkbk.Sheets(1).Name <> WSName Then
newwkbk.Sheets.Add.Name = WSName
End If
Next
Code:
Sheet1(Script)
Sheet6(Stats)
Code:
Sheet1(Script)
Sheet2(Stats)
Thanks