macro problem occurring after saving & reopening file

sschwant

Board Regular
Joined
Jul 31, 2008
Messages
66
Hello, I have a daily time tracking file with a macro that adds a new tab with date + 1.
This is the code:
VBA Code:
    Sub Add_New_Sheet()
    Application.ScreenUpdating = False
    Dim wshL As Worksheet
    Dim wshN As Worksheet
    Dim d As Date
    Set wshL = Worksheets(Worksheets.Count)
    d = DateValue(wshL.Name)
    wshL.Copy After:=wshL
    Set wshN = ActiveSheet
    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

1) Rather than have the new sheet inserted at the end right of the work book or after the latest date; I'd prefer to have it inserted at the beginning or at least before the latest date.
2) When ever I save, close, and reopen the file I run into issues and the file has to be 'repaired' and I'm not sure why this is happening:

Tracker Error Message.PNG


The "Template" sheet referenced in the code has two tables: one is just a regular table with data validation drop down list for activities with time in 15" increments, and the other is a pivot table of the first table which summarizes the activity counts and sums the hours. As this process iterates, clearly a lot of tables are getting created but not sure why this problem keeps occurring.

Grateful for any insights/guidance!

Thanks,
Steve
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top