+ Reply to Thread
Results 1 to 13 of 13

Selecting multiple sheets for a "assign-label-code"

  1. #1
    Registered User
    Join Date
    10-23-2014
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    21

    Selecting multiple sheets for a "assign-label-code"

    Hi guys,


    I have multiple excel sheets with names like:
    PG1 2013
    1. brand 2012-2013-10. brand 2012-2013 and more.

    I would like your help with one of these suggetions:

    1. Run this code on only the excel sheets that need labels to be assigned
    Or
    2. Run the code on all sheets even though far from all need a label assigned.

    Code

    Please Login or Register  to view this content.
    How can I run this code on multiple sheets or all of them without making a code that is 3 pages long..
    The code works on each individual, but since it's going to be a part of button I need "it" to know what sheets to be run on.

    Thank you in advance.
    Last edited by jakobharms; 10-23-2014 at 06:36 AM. Reason: Violation of rule 3.

  2. #2
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Selecting multiple sheets for a "assign-label-code"

    And how is the code to know which sheets need labels assigned?
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

  3. #3
    Registered User
    Join Date
    10-23-2014
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    21

    Re: Selecting multiple sheets for a "assign-label-code"

    Hi Natefarm,

    That's my problem, I recorded this and been using it via hotkey and just played it on each chart I where I needed to assign labels.
    So the question is, can I make a code that applies to all my sheets or should I include each sheet's name in a "phrase" with the code I already have?
    As you can tell i'm quite new to vba.

    Thank you.

  4. #4
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Selecting multiple sheets for a "assign-label-code"

    The following will loop through each sheet in your workbook and apply labels. If the sheet doesn't have a chart, or the label code fails for some other reason, it will just move on to the next.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Selecting multiple sheets for a "assign-label-code"

    One way might be:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-23-2014
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    21

    Re: Selecting multiple sheets for a "assign-label-code"

    Thanks a lot for both suggestions.

  7. #7
    Registered User
    Join Date
    10-23-2014
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    21

    Re: Selecting multiple sheets for a "assign-label-code"

    Hi Natefarm,

    I tried your suggestion but get this message:
    Run-time error '1004':
    Method 'Select' of object' _Worksheet' failed

    There's a lot hidden sheets, can they disrupt the code or what should I look for?

    Thank you.

  8. #8
    Registered User
    Join Date
    10-23-2014
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    21

    Re: Selecting multiple sheets for a "assign-label-code"

    Hi John,

    I get this error when using your code:
    Run-time error '13':

    Type mismatch

    NB: I used your code and put in the name of the first sheet that needs labels to be assigned.

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Selecting multiple sheets for a "assign-label-code"

    Yes, you can't select hidden sheets. Are the charts on hidden sheets? If not, you might add "if ws.visible then ... ". If they are hidden, and you still want the labels added, set ws.visible = false first, then reset to true later if needed.

  10. #10
    Registered User
    Join Date
    10-23-2014
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    21

    Re: Selecting multiple sheets for a "assign-label-code"

    All the charts are in fact on unhidden sheets and the data that creates the charts are hidden, but since i'm only adding labels that should not interrupt the code if only select sheets that are visible?

    So the new code is like this:

    Please Login or Register  to view this content.
    Thank you once again.

  11. #11
    Registered User
    Join Date
    10-23-2014
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    21

    Re: Selecting multiple sheets for a "assign-label-code"

    All the charts are in fact on unhidden sheets and the data that creates the charts are hidden, but since i'm only adding labels that should not interrupt the code if only select sheets that are visible?

    So the new code is like this:

    Please Login or Register  to view this content.
    Thank you once again.
    Last edited by jakobharms; 10-27-2014 at 05:50 AM. Reason: Error.

  12. #12
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Selecting multiple sheets for a "assign-label-code"

    No, you have it backwards

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    10-23-2014
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    21

    Re: Selecting multiple sheets for a "assign-label-code"

    Thanks once again. I found a solution that was more appropriate.

+ 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. Replies: 3
    Last Post: 04-16-2014, 10:00 AM
  2. [SOLVED] Assign Categories for Time of Day: "Morning", "Afternoon", "Evening"
    By long_shanks in forum Excel General
    Replies: 3
    Last Post: 06-11-2013, 02:59 AM
  3. Replies: 2
    Last Post: 06-06-2013, 12:45 PM
  4. [SOLVED] scatter plots and "label" as ("X" value1, value2)
    By shabnam in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 04-11-2005, 10:06 AM

Tags for this Thread

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