Problem inserting new worksheet in Excel daily time tracker w/ date format (at specific location in book)
I have the following code:
Code:
Sub
Application.ScreenUpdating = False
Dim wshL As Worksheet
Dim wshN As Worksheet
Dim wshP As Worksheet
Set wshP = Worksheets("Activities & Macro")
Dim d As Date
' Set wshL = Worksheets(Worksheets.Count)
' d = DateValue(wshL.Name)
' wshL.Name = Format(d + 1, "mm-dd-yy")
wshL.Copy After:=Worksheets("Activities & Macro")
Set wshN = ActiveSheet
d = DateValue(wshL.Name)
wshN.Name = Format(d + 1, "mm-dd-yy")
Worksheets("Template").Columns("B:D").Copy wshN.Range("A1")
wshN.Range("E2").PivotTable.SourceData = _
wshN.Range("A1").CurrentRegion.Address(, , xlR1C1, True)
ActiveWindow.Zoom = 90
Application.ScreenUpdating = True
End Sub
My file is used for daily productivity & time tracking and is almost working as I'd like. Originally the macro would place the new sheet to the far right of all sheets in the book, but as it's iterated over the last month or so it's getting cumbersome to keep scrolling all the way to the left to the tab with my macro button ("Activities & Macro"). So, I started tinkering with a new file in which only 3 tabs to start: "Template", "Activities & Macro", and "08-05-20".
When I run the macro a new sheet is created right after the Activities & Macro tab as I'd like (this would mitigate the need to keep scrolling left after a new day/date tab is inserted). However, then there's a break down ... 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).
If I run macro again I end up with: 08-07-20 (2), 08-06-20, and 08-07-20 so now what was 08-06-20 is now 08-07-20 and the new sheet is 08-07-20 (2). This would iterate perpetually with every new sheet as a duplicate. Also, once the date is set - it should be static; e.g., first date = 08-05-20, next = 08-06-20, next = 08-07-20 so on for time tracking purposes ...
What am I missing? Thanks!
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=313859#p313859
https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=313855#p313855
https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=313848#p313848
https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=313843#p313843
https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=313792#p313792
https://www.eileenslounge.com/viewtopic.php?f=30&t=40560&p=313771#p313771
https://www.eileenslounge.com/viewtopic.php?f=30&t=40560&p=313767#p313767
https://www.eileenslounge.com/viewtopic.php?f=30&t=40560&p=313746#p313746
https://www.eileenslounge.com/viewtopic.php?f=30&t=40560&p=313744#p313744
https://www.eileenslounge.com/viewtopic.php?f=30&t=40560&p=313741#p313741
https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=313622#p313622
https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=313575#p313575
https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=313573#p313573
https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=313563#p313563
https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=313555#p313555
https://www.eileenslounge.com/viewtopic.php?f=30&t=40533
https://www.eileenslounge.com/viewtopic.php?f=39&t=40265&p=313468#p313468
https://www.eileenslounge.com/viewtopic.php?f=42&t=40505&p=313411#p313411
https://www.eileenslounge.com/viewtopic.php?f=32&t=40473&p=313384#p313384
https://www.eileenslounge.com/viewtopic.php?f=30&t=40501&p=313382#p313382
https://www.eileenslounge.com/viewtopic.php?f=30&t=40501&p=313380#p313380
https://www.eileenslounge.com/viewtopic.php?f=30&t=40501&p=313378#p313378
https://www.eileenslounge.com/viewtopic.php?f=32&t=40473&p=313305#p313305
https://www.eileenslounge.com/viewtopic.php?f=44&t=40455&p=313035#p313035
https://www.eileenslounge.com/viewtopic.php?f=18&t=40411&p=312889#p312889
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
Problem inserting new worksheet in Excel daily time tracker w/ at specific location
Alan,
Thanks - your code is working, but isn't exactly what I was trying to do ... My file is meant to be a daily time tracker. There are 4 tabs to start:
1) "Task List" - this is static and for reference only,
2) "Activities & Macro" - also static w/ a button to launch the macro,
3) "Template" - also static, but meant to be copied as a new date formatted daily tracker/time keeper. It has a table w/ 3 columns B: time by by 15 minute increments, C: data validation drop down list referring to the list of activities on the tab # 2, and D: hours = 0.25 per row.
4) "08-09-20" - first date formatted tab. To start this can be blank (I think). Ultimately though it would be a copy of the Template tab but w/ a simple Pivot Table appended to it - which summarizes the activities by a sum of hours and count of activities - which is included in the code already.
The goal is to have the template copied as a new date formatted tab w/ the pivot table, inserted to the right of the Activities & Macro tab. Then as the cycle iterates - all previous dates are pushed off to the right. Initially, all new sheets were inserted at the far right of the workbook, but as the process iterates, it gets cumbersome to keep scrolling way left to get back to the macro button on the Activities & Macro tab.
So, is there are a way to edit your macro such that it copies the template?
Thanks!
Steve