+ Reply to Thread
Results 1 to 7 of 7

Check names on every sheet

  1. #1
    Registered User
    Join Date
    01-01-2010
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    34

    Check names on every sheet

    In a large (and constantly changing) Excel file I would like to check which worksheets do have the named range “Obj_Nr”. Next step would be to run another macro only on these worksheets.

    I am trying to get a list of worksheet numbers which meet the required name (like sheet 2, 3, 5 and 8).

    I tried the following code:
    Please Login or Register  to view this content.
    First I thought the problem was this NamedRange always has the worksheet name in front of it (like ‘Sheet1’!Obj_Nr and ‘Sheet2’!Obj_Nr). This would hopefully be solved by the * in front of the search term "*Obj_Nr".

    Unfortunately the macro is stuck at this line:
    Please Login or Register  to view this content.
    Does anybody know what I am doing wrong here?

    Thank you in advance.
    Erik
    (The Netherlands)

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Check names on every sheet

    I just tried this which will highlight which sheets have a named range like that and it seems to work okay. Hopefully you can adapt:

    Please Login or Register  to view this content.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    01-01-2010
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    34

    Re: Check names on every sheet

    Thank you for advice. This indeed works to help me identifying the worksheets which contain this name. But I don't know how to make a list of these worksheets in order to use the numbers in another macro.
    Is is possible to 'store' the hits in the macro's memory?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Check names on every sheet

    Hello ESF,

    This macro will return the worksheet numbers as a comma separated string. Later, you can then use the Split function to separate the sheet numbers into an array.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    01-01-2010
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    34

    Re: Check names on every sheet

    Thank you very much! When I run this code step-by-step with F8 I can see the result is perfect. In the code I can see GetSheetNumbers = "7,8,9" when I hold the mouse above it.

    In another macro I followed your advice with the split command.
    Please Login or Register  to view this content.
    Unfortunately now I am stuck at the second line. Do you know my error here?

    Thank you in advance

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Check names on every sheet

    Hello ESF,

    Here is the corrected code. "Sheet" is a VBA keyword. I changed it to "Sht".
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-01-2010
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    34

    Re: Check names on every sheet

    Thank you again Leith Ross. This code is working perfect and exactly what I hoped it would do. Now I'll try to improve/expand it myself.
    Last edited by ESF; 12-17-2010 at 02:55 AM. Reason: Solved

+ 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