+ Reply to Thread
Results 1 to 6 of 6

Add additional text within copied sheet name brackets

  1. #1
    Registered User
    Join Date
    11-17-2008
    Location
    UK
    MS-Off Ver
    Pro Plus 2019
    Posts
    22

    Add additional text within copied sheet name brackets

    Hi,

    I have 2 scenarios that I am trying to cater for both which work well but I am trying to tweak one to facilitate reporting later on.

    The first allows me to copy a sheet to the workbook from a hidden "template" sheet then rename it to the name of the current sheet and then auto number the new sheet in sequence.

    Example - Scenario 1
    1. Template sheet called My template and hidden
    2. Active sheet called (Test)
    Code then
    Copies a sheet to workbook based on template and rename's it to Test 1
    Code again would add template sheet and rename sheet Test 2 etc.

    Scenario 2
    Using just the ActiveSheet.Copy After:=ActiveSheet allows me to take the active sheet and then in excel fashion add Sheet name and then number in brackets.

    This again is fine but i was wondering if there is anyway of having fixed text within the brackets preceeding the number

    Example

    Active sheet..........Test 1
    Result of copy....... Test 1 (1)
    Result of another copy...... Test 1 (2)
    Etc.

    I am trying to to get it so I can have a result like this...

    Active sheet..........Test 1
    Result of copy....... Test 1 (Option 1)
    Result of another copy...... Test 1 (Option 2)
    Etc.

    The actual copy is perfect but later processes and reporting will be much improved and identified if I could add "Option" within the bracketed number which is being generated by the ActiveSheet.Copy After:=ActiveSheet code.

    The other nice thing about this for me is that all sheets are displayed correctly in sequence as the book is built up.

    (On site survey form)

    I just can't see where I can add the additional text as it seems it's just the way excel deals with the copy and nothing that I can pick apart.

    Any thoughts greatly received

    Dean

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Try this:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    11-17-2008
    Location
    UK
    MS-Off Ver
    Pro Plus 2019
    Posts
    22
    Hi,

    Thank you very much for your time. I have just tried the code having replaced the sheet names for the proper ones in my project but It has returned an error at this point:

    Function SheetExists(vWks As Variant, Optional wkb As Workbook) As Boolean

    I've tried to check through again to make sure I haven't mixed up my sheet names anywhere but all seems to be correct.

    Am I correct in having the Function section in the same module.
    I have literally pasted the code as is straight into a new module and linked my button to it to run.

    Where should I be looking?

    Thank you

    Dean


    Whoooooops!

    Didn't pick up the last line
    End Function with the copy! Doh!

    OK, so, code runs without errors but no new sheet is appearing!


    Ha HA ! Sorry, flicking about the book at the moment, was just going to rename my hidden template sheet so as not to have any spaces in the name and just Just found my "new sheets".

    The code is running but seems to be creating the sheets and then hiding them!

    At what point would I slot in the code to make the sheet "just created" visible and sitting after the active sheet being copied?

    Kind Regards

    Dean
    Last edited by DeaJL; 12-16-2008 at 09:48 PM. Reason: Additional Info!

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    No time to test, Dean, but try this as the last line (before End Sub) in AddSheet:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-17-2008
    Location
    UK
    MS-Off Ver
    Pro Plus 2019
    Posts
    22
    OK,

    The code seems to be creating the sheet in a hidden state.
    I have just played with creating the sheets and have found the following:

    each time the code creates the new copy it appears to be always basing it on the hard coded sheet name (Test 1)

    I think I'm right in saying that I have a variant here?

    The Hidden template sheet I have is actually called New Location
    The code which adds me a New Location takes this hidden sheet and then renames it to the last New location +1.....


    Example
    Run code on Hidden sheet called "New Location", get new active and visible sheet called Location 1.

    Run code again get another new active and visible sheet called Location 2

    Etc.

    What I'm wanting to do now is duplicate any particular Location sheet that I have created as above and filled out (could be Location 1, could be location 4 etc.

    but with this macro, just duplicate the sheet I run it on and have it place the copy of itself to the right of this active sheet

    The way Excel name's the sheet during this process duplicates the sheet name in full (which is fine) and then adds the (1), (2), etc. at the end as you run the macro over and over.

    This is the bit I am trying to tap into and add the word Option behind excel's end number to my sheet name which it puts in the brackets.


    I hope this makes sense.

    Deano

  6. #6
    Registered User
    Join Date
    11-17-2008
    Location
    UK
    MS-Off Ver
    Pro Plus 2019
    Posts
    22
    Wow,

    Getting there.

    Sheets now visible but as I just mentioned, the copy is always basing it'self on the hardcoded sheet name.

    If I happen to be running this on Location 1 then all is good.

    If I then happen to run it on Location 4 say, then I get the next "Option number" but it is still being numbered on Location 1

    Thank you so much for your time here I'm really grateful

    Regards

    Dean

+ 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