+ Reply to Thread
Results 1 to 9 of 9

Reset New Worksheet Numbering in Macro

  1. #1
    Registered User
    Join Date
    09-25-2008
    Location
    Scotland
    Posts
    12

    Reset New Worksheet Numbering in Macro

    I have a large macro doing multiple things only problem is that i can only run it once then have to shut down and open again if i want to run it again. The reason for this is that part of the macro creates new worksheets, and when the new worksheet is created it is automatically numbered as Sheet 1, Sheet 2 etc for a few new worksheets.

    My problem is when i run it a second time the new work sheets will be created as the next number in the sequence.

    i.e. the first round creates 2 new worksheets nameed Sheet 1 and Sheet 2, my macro references Sheet 1 and Sheet 2. How ever when i run it agian, it deletes Sheet1 and Sheet 2 and creates Sheet 3 and Sheet 4. My macro does not reference Sheet 3 and Sheet 4. You see my problem.

    Everytime i shut excel down it resets the numbering, is there anyway to do this in my macro without shuting down excel?
    Last edited by Colin_S; 08-16-2010 at 05:22 AM.

  2. #2
    Registered User
    Join Date
    08-12-2010
    Location
    Dublin
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Reset New Worksheet Numbering in Macro

    Quote Originally Posted by Colin_S View Post
    I have a large macro doing multiple things only problem is that i can only run it once then have to shut down and open again if i want to run it again. The reason for this is that part of the macro creates new worksheets, and when the new worksheet is created it is automatically numbered as Sheet 1, Sheet 2 etc for a few new worksheets.

    My problem is when i run it a second time the new work sheets will be created as the next number in the sequence.

    i.e. the first round creates 2 new worksheets nameed Sheet 1 and Sheet 2, my macro references Sheet 1 and Sheet 2. How ever when i run it agian, it deletes Sheet1 and Sheet 2 and creates Sheet 3 and Sheet 4. My macro does not reference Sheet 3 and Sheet 4. You see my problem.

    Everytime i shut excel down it resets the numbering, is there anyway to do this in my macro without shuting down excel?
    Assuming I understand you right, the simplest thing to do would be to give the sheets a name when they're created.

    E.g. when you create the sheets:

    Please Login or Register  to view this content.
    Then instead of referencing Sheet1 and Sheet2, refer to Colin1 (or whatever you want to call it) and Colin2.

    E.g.
    Please Login or Register  to view this content.
    etc

  3. #3
    Registered User
    Join Date
    09-25-2008
    Location
    Scotland
    Posts
    12

    Re: Reset New Worksheet Numbering in Macro

    Thanks but the problem with that is that they are created from a pivot table i.e.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Reset New Worksheet Numbering in Macro

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    09-25-2008
    Location
    Scotland
    Posts
    12

    Re: Reset New Worksheet Numbering in Macro

    Ok attached a dummy file. This is a very much cut down version of what i'm trying to do and the information on the detail page changes every time i run the full macro.
    Attached Files Attached Files

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Reset New Worksheet Numbering in Macro

    You will keep getting problems you are hard coding sheet names & ranges, which may change

    I can't really follow what you are trying to do

  7. #7
    Registered User
    Join Date
    09-25-2008
    Location
    Scotland
    Posts
    12

    Re: Reset New Worksheet Numbering in Macro

    I wouldn't normally hard code sheet names but the way you generate new sheets from a pivot table I can't see another option.

    What I’m trying to achieve is that the first part of my macro pulls data from 6 different workbooks into one sheet. I have 9 people who own the data and need to do work on it so am using a pivot table to create a summary of the detail and then creating 8 new worksheets for each person.

    It works fine the first time i open the file, and maybe that's how it will have to stay, but would prefer if there was some way to recent the automatic number of new worksheets.

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,973

    Re: Reset New Worksheet Numbering in Macro

    Store activesheet in a worksheet variable immediately after it is created.
    Everyone who confuses correlation and causation ends up dead.

  9. #9
    Registered User
    Join Date
    09-25-2008
    Location
    Scotland
    Posts
    12

    Re: Reset New Worksheet Numbering in Macro

    Thanks romperstomper, that's not what i did but it made me realise how easy it was to fix. I just renamed the active sheet when it is created, sorted!!!!

    Cheers for everyone's help

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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