+ Reply to Thread
Results 1 to 4 of 4

controlling sheet names when adding sheets to a workbook in a macro

  1. #1
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    controlling sheet names when adding sheets to a workbook in a macro

    Hi,

    I am adding sheets into a workbook (many sheets controlled by some constant values in one tab).

    When I did a simple recording of the keystrokes I found this command was recorded
    Please Login or Register  to view this content.
    This seems to work pretty well on the first time I use it in a newly opened workbook and I get sheet names I can rely on (Sheet1, Sheet2 etc) as I then need to rename them in my macro.

    What puzzles me is that if I then delete the sheets I have added (say I added 20) and rerun the macro the first sheet is showing as "Sheet21". If I simply delete the initial sheets, save the workbook, close the workbook and re-open it then I get "Sheet1" again

    I am guessing there must be a property that I can set to control the name of the next sheet I add without needeing to close and reopen the workbook

    Hope this makes sense, look forward to any help

    jmac1947

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: controlling sheet names when adding sheets to a workbook in a macro

    Hi, jmac1947,

    why not rename them directly after adding them as the new sheet will be the active one by then? Or set an object to them and use that? Collect the new names in a Collection/Dictionary/Array?

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,925

    Re: controlling sheet names when adding sheets to a workbook in a macro

    Please Login or Register  to view this content.
    Ben Van Johnson

  4. #4
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: controlling sheet names when adding sheets to a workbook in a macro

    Thanks to both of the replies, in my very limited VBA knowledge I opted for the solution from protonLeah
    (it seemed the simple way) and sure enough it worked.

    I learnt something new and finished my macro (double bonus)

    Again thanks

    Jmac

+ 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. extrac data from different sheets by sheet name and copy the workbook names
    By ripple in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-31-2013, 11:26 AM
  2. Replies: 1
    Last Post: 01-08-2013, 03:38 AM
  3. [SOLVED] Macro copying values and sheet names of all activated sheets
    By Rosixks in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-07-2011, 06:16 PM
  4. Excel 2007 : controlling sheet tab names
    By Doughover in forum Excel General
    Replies: 4
    Last Post: 03-06-2010, 02:54 PM
  5. Replies: 5
    Last Post: 11-26-2006, 09:37 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