+ Reply to Thread
Results 1 to 8 of 8

help with code to create a new sheet each quarter

  1. #1
    Registered User
    Join Date
    01-22-2014
    Location
    Potosi, MO
    MS-Off Ver
    Excel 2013
    Posts
    64

    help with code to create a new sheet each quarter

    My goal is this:
    Macro to run every 3 months, copy the workbook its in, save as a new name, and then delete all of the tabs in the workbook except for the "Menu" tab?

    however. I get errors with my code below. Could anyone help me test / fix the code?


    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: help with code to create a new sheet each quarter

    You had a typo, and you need to use SaveCopyAs instead of SaveAs, and it is better to not have .xlsm in the name string other than as the extension.

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 04-21-2014 at 11:51 AM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    01-22-2014
    Location
    Potosi, MO
    MS-Off Ver
    Excel 2013
    Posts
    64

    Re: help with code to create a new sheet each quarter

    Im still having issues with this one. No error poping up, its making a copy, but I can't see anything in the copy that it made. Also, its not deleteing the tabs from the original table. Ideas?

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: help with code to create a new sheet each quarter

    I think that you have the logic backwards - the code is keeping all tabs in the file with the date in its name, and deleting all but the Menu sheet from the file with the original name. At least that is how it works for me... I did not change the logic, just the code to not get errors.

  5. #5
    Registered User
    Join Date
    01-22-2014
    Location
    Potosi, MO
    MS-Off Ver
    Excel 2013
    Posts
    64

    Re: help with code to create a new sheet each quarter

    How would it go to copy the original sheet, and give it the new name with the date...changeing nothing else... And then in the original, delete all of the tabs except for the menu tab.

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: help with code to create a new sheet each quarter

    I don't know what to tell you except that is what I think it does - a copy of the original workbook is saved with a date stamp in its name, and then all sheets but Menu are deleted, and the original workbook is saved as a one-sheet workbook. If you post an original workbook, a date-stamped version of the workbook, and the post-macro version of the original workbook, then maybe....

  7. #7
    Registered User
    Join Date
    01-22-2014
    Location
    Potosi, MO
    MS-Off Ver
    Excel 2013
    Posts
    64

    Re: help with code to create a new sheet each quarter

    Well, it seems like if I run the macro manually, that it is working correctly. But if I try to have it run from workbook open, automatically that I get bad results.

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: help with code to create a new sheet each quarter

    That's because the code is not designed to run in the workbook open event. You will never be able to open the copy or the workbook - but you will get more and more files created. You need to have a way out of the code if it has already run or is running in a copy of the workbook. So run it manually, as it was designed.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. why how does this code create a new sheet after the last line of code...
    By tconnell1965 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2013, 06:23 AM
  2. create new workbook and sheet with vba code in it
    By runTNT in forum Excel General
    Replies: 8
    Last Post: 04-07-2011, 02:35 AM
  3. Code to create copies of a 'template' sheet
    By Palaeontology in forum Excel General
    Replies: 6
    Last Post: 04-17-2010, 03:11 PM
  4. Fiscal Quarter code not working
    By Robert in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-01-2006, 03:40 PM
  5. Code to create and name a sheet
    By dogpigfish in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-04-2006, 11:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1