Hi,
I have a workbook for each qtr. Each book is to have a single sheet for each week. These sheets will be named after the ISO week number i.e. Week1, Week2 etc. At the start of the qtr, there will be just one sheet...say Week26...each Monday a copy is to be made of the last sheet and the week number incremented by one...i.e. copy the sheet and all it's contents from Week26 to Week27.
I'm new to VBA and have been searching this forum and have some great code...can't seem to get the right thing to increment by one though...any help?
Last edited by racton; 10-14-2011 at 11:32 AM.
Two lines like this ought to do it for you:
currentsheetnum = Application.WorksheetFunction.Substitute(ActiveSheet.Name, "Week", "") NewSheetName = "Week" & currentsheetnum + 1
From a logic standpoint, when you know the "string to remove to get the number" is consistent:
Dim NewShtName As String, OldShtName As String OldShtName = Sheets(Sheets.Count).Name NewShtName = "Week" & Replace(OldShtName, "Week", "") + 1 Sheets(OldShtName).Copy after:=Sheets(Sheets.Count) ActiveSheet.Name = NewShtName
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
Many thanks for the post. Really appreciated.
many thanks...and so simple ;-)
If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks