+ Reply to Thread
Results 1 to 7 of 7

How to zero worksheet index?

  1. #1
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    How to zero worksheet index?

    Hello,

    My macro creates (and names) and then deletes rather large number of worksheets in each iteration.

    Recently I've noticed that although names are given properly (through a loop) the index is not zeroing but keep growing and growing.

    I will add that the macro works just fine but I'm not sure it's healthy that the sheet's index getting so big (I assume so at least).

    Any idea how to set the index to 0?

    Here is the code that deletes each iteration active worksheets.

    Please Login or Register  to view this content.
    Please * if you like the answer

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: How to zero worksheet index?

    Do you need L defined?

    Please Login or Register  to view this content.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to zero worksheet index?

    What index are you referring to?
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to zero worksheet index?

    @Norie to your question, nathan:

    This is the "core" of the code, where P column is a result of remove duplicates operation, and for each unique value in column P after the removal a new worksheet should be created, and named.

    The delete macro (in my first post) just needs to "clear" after closing.

    ***As I'm sure Norie at least knows by heart LIN is just the name of a worksheet***

    Please Login or Register  to view this content.
    Last edited by GIS2013; 07-16-2014 at 10:29 AM. Reason: Tyop and more

  5. #5
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: How to zero worksheet index?

    The code i have supplied, is triggered on adding a new sheet to Excel workbook, so just needs to be put in the thisworkbook code module, when you add a sheet, if there are 3 already then it will be called sheet(3+1)=sheet4.

  6. #6
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to zero worksheet index?

    @nathan, could you tweak my code in accordance? I'm a bit confused how it would not be problematic for me as I need the new sheets' names to be P values.

    For example if P column contains P2:P7 = 100:105, then need to create 6 new worksheets, named 100,101,...,105.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to zero worksheet index?

    Why not create a reference to the worksheets as you add them?
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to zero worksheet index?

    Thanks Norie: your code is simpler than mine .

    Results: when I open the workbook and run the "fixed" "core" code the sheets' count is from 0 (sheet 1,..,sheetX), actually X is the value of the last cell in column P (after removing duplicates).

    But then after using the delete macro (first post here) and then the "core" again, in the porject window I see that the sheets count begins in sheetX+1.

    Nevertheless closing the workbook sets the count to 0. And since I assume the end-user will close the workbook from time to time, I hope the index is not going to go hysterical.

+ 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. [SOLVED] Replacing a referenced worksheet name with a variable worksheet index number.
    By sdavison in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-01-2013, 09:49 AM
  2. Replies: 0
    Last Post: 04-24-2013, 11:24 PM
  3. worksheet object as string - loop statement in worksheet index
    By ag273n in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2013, 12:27 PM
  4. counting the worksheet index
    By burugudug in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2010, 04:59 AM
  5. INDEX(MATCH using value from one worksheet to locate data in another worksheet
    By ACurtis802 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-16-2009, 04:59 AM

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