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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,223,374
Messages
6,171,713
Members
452,418
Latest member
kennettz

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