Hello sschwant
Welcome to ExcelFox
Your current macro renames the last worksheet to a new ( day +1 ) date and then copies it. So this … Tab 08-05-20 gets renamed as 08-06-20 and the new sheet (inserted after Activities & Macro tab) is named 08-06-20 (2) …. is exactly what I would.
Code:
Set wshL = Worksheets(Worksheets.Count) ' Last tab
d = DateValue(wshL.Name) ' date value of current last tab name
wshL.Name = Format(d + 1, "mm-dd-yy") ' add 1 day to date value and rename last tab name to that new date
wshL.Copy After:=Worksheets("Activities & Macro") ' copy the last tab
Your macro then renames the new worksheet to a new date( day +1 ) of the already renamed worksheet) date.
So the new worksheet gets a date two days ahead of the original last worksheet, and that original worksheet has a date one day ahead
Code:
d = DateValue(wshL.Name) ' the original last tab has already had its name changed to one day ahead
wshN.Name = Format(d + 1, "mm-dd-yy") ' the new worksheet gets a name another day ahead, two days in total above the original last worksheet
Originally Posted by
sschwant
What am I missing?
I can’t tell you what you are missing, because you have not explained you want to do.
Let me take a stab at guessing what you might want to do, ......
I will assume that after running the macro, the new worksheet with the newest date is the third worksheet, after the second worksheet ( Activities & Macro ) . Effectively then all the other worksheets get shifted to the right. - So you would end up with something like this:
Newest at Third tab.JPG : https://imgur.com/RZ1h9l4
Newest at Third tab.JPG
This macro does that:
Code:
Sub Test2() ' https://excelfox.com/forum/showthread.php/2609-Problem-inserting-new-worksheet-in-Excel-daily-time-tracker-w-date-format-(at-specific-location-in-book)?p=14763#post14763
Dim wshL As Worksheet, wshN As Worksheet, wshP As Worksheet
Set wshP = Worksheets("Activities & Macro")
Set wshL = Worksheets.Item(3) ' 3rd tab worksheet
Dim d As Date
Let d = DateValue(wshL.Name) ' date value of current third tab
wshL.Copy After:=Worksheets("Activities & Macro") ' copy the third tab, place the new copy at the third tab position, ( which will shift all other worksheets after it one space to the right )
Set wshN = ActiveSheet ' This is the newely added worksheet
wshN.Name = Format(d + 1, "mm-dd-yy") ' the new worksheet gets a name of 1 day above the previous newest worksheet
' Worksheets("Template").Columns("B:D").Copy wshN.Range("A1")
' wshN.Range("E2").PivotTable.SourceData = _
' wshN.Range("A1").CurrentRegion.Address(, , xlR1C1, True)
' ActiveWindow.Zoom = 90
End Sub
Alan
( cross post : https://www.excelforum.com/excel-pro...-location.html
https://www.mrexcel.com/board/thread...-file.1142030/ )
Bookmarks