+ Reply to Thread
Results 1 to 6 of 6

Copied numbered Sheet based upon cell value

  1. #1
    Registered User
    Join Date
    01-24-2016
    Location
    Liverpool, England
    MS-Off Ver
    Office Pro Plus 2013
    Posts
    13

    Copied numbered Sheet based upon cell value

    Hi folks,
    I can usually find the information on these forums that I'm after, but this time I have come up dry..

    I'm looking for a VB formula that will duplicate a sheet based on a cell value. The cell value will be a number (1-12) and the sheets have all been renamed to numbers (1-12).

    I'd like the formula to; IF G1 (from a sheet named 'Fighter Data') = 2 THEN DUPLICATE SHEETNAME "2".

    Thanks in advance lovely people.

    Dean

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,628

    Re: Copied numbered Sheet based upon cell value

    try:
    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    01-24-2016
    Location
    Liverpool, England
    MS-Off Ver
    Office Pro Plus 2013
    Posts
    13

    Re: Copied numbered Sheet based upon cell value

    Hi Kaper,
    Thanks for the fast response. I am getting 'subscript out of range'. Please see attached.

    Regards

    Dean
    Attached Files Attached Files

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,628

    Re: Copied numbered Sheet based upon cell value

    There was an error in address (G2 not G1 !) (it was in my original post, which I edited probably 30 seconds after posting :-) )
    By the way there are 2 other minor items
    - as you use SUBTOTAL in G1 (which returns number not text, it will be wiser to use value from that cell converted to text.
    - I see no point to insert this macro in ThisWorkbook module, not in standard module.

    Best,
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-24-2016
    Location
    Liverpool, England
    MS-Off Ver
    Office Pro Plus 2013
    Posts
    13

    Re: Copied numbered Sheet based upon cell value

    Hi Kaper,
    Thanks for the help. I think I need to teach myself VBA as I'm rubbish at that/ Why would you say put the code in the sheet rather than the module? What detriment would it have? And since we are referencing 'G1' would that mpt already be referencing that cell? How would making it text be any better?

    Thanks in advance

    Dean

  6. #6
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,628

    Re: Copied numbered Sheet based upon cell value

    Hi number of questions, only few easy answers:
    1) I've not said to put code in the sheet. Just opposite, I suggested to put it in standard module (Module1) - It was originally in workbook code (which in this case made no harm, but is not a good practice). In the Workbook code is a standard place to keep event handlers for workbook events (happening on open, beforeclose, beforeprint, activate etc.). All standard code would fit fine in standard code module.
    2) converting to text. Name of the sheet is text. But Sheets(variable) accepts both text with sheetname and just number as an index. so if your workbook have 3 sheets named" 3, SheetX and Summary
    Sheets(3).activate will activate third sheet named Summary, while Sheets("3").activate will activate first sheet named 3.

+ 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. inserting a copied row based on the value in a cell
    By victor4620 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2016, 03:46 PM
  2. Replies: 0
    Last Post: 05-10-2016, 01:32 PM
  3. Adding new rows based on a numbered value in another cell
    By Faulkes2 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-13-2014, 07:00 PM
  4. Replies: 1
    Last Post: 09-04-2014, 12:59 AM
  5. Fill cell based on a numbered list
    By nokia6100 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-02-2014, 12:40 PM
  6. Replies: 4
    Last Post: 05-11-2013, 07:12 AM
  7. [SOLVED] Copy sheet based on Inputbox - data to be copied variable.
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 09-07-2012, 10:40 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