+ Reply to Thread
Results 1 to 12 of 12

Looping through worksheets defined in named range

  1. #1
    Registered User
    Join Date
    09-10-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    61

    Looping through worksheets defined in named range

    This is a really simple question, but I can't seem to find any solution from any forums. Or I might be searching on wrong keywords.

    I have a number of sheets in the workbook

    Let say,

    Sheet names
    Chapter 1
    Chapter 2
    Chapter 3
    Synopsis
    Summary

    I have set a named range ("SheetsToChk") that refers to cell that I have entered the names of the sheets I want the macro to loop through.
    For e.g:
    Chapter 1
    Chapter 2
    Chapter 3


    I have also tried the code below, but the Macro just don't go to any other sheets. Please advise me how I can do a loop through worksheets that I have specify in the named range that I have set?
    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Looping through worksheets defined in named range

    try this loop
    Please Login or Register  to view this content.
    i used msgbox because i dont have mycode
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    09-10-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Looping through worksheets defined in named range

    is it possible to refer to the named range set instead of checking if sheets' name start with Chapter?

    as it does not always start with chapter...

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Looping through worksheets defined in named range

    Please Login or Register  to view this content.
    variation based on (named) range
    wsl to your named range

    however you need to define what your checking against ultimately
    Last edited by humdingaling; 08-21-2013 at 03:11 AM. Reason: ps wsl doesnt mean nothing i just needed another variable =)

  5. #5
    Registered User
    Join Date
    09-10-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Looping through worksheets defined in named range

    I just want to go through each of the worksheet specified in the named range let say ("sh_pull")
    and execute my code in each of those sheet.

    I don't want the check value that starts with "chapter"...

    i tried to just put

    Please Login or Register  to view this content.
    but fails. it kept saying i have mismatch

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Looping through worksheets defined in named range

    then just take out the if statement on post #4

  7. #7
    Registered User
    Join Date
    09-10-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Looping through worksheets defined in named range

    i tried but still doesn't work.

    I have attached the sample i'm working on.
    loopthrusheets.xlsm

    when i run the macro, it only put the word "title" on the sheetname "master" instead of what I have defined in the name range "sh_chk" for chapter 1,2 and 3.

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Looping through worksheets defined in named range

    you took out too much of the code
    see attached

    Run macro Chk2
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    09-10-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Looping through worksheets defined in named range

    thanks so much, it finally works!

    could you explain what is the 'replace' for?

    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Looping through worksheets defined in named range

    the value it takes comes with " " around the sheet name
    ie "Chapter 3"
    replace is to remove the "

  11. #11
    Registered User
    Join Date
    09-10-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Looping through worksheets defined in named range

    Thanks alot, appreciate your guidance.


  12. #12
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Looping through worksheets defined in named range

    sure thing
    not a problem
    thanks for the rep

+ 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. [SOLVED] Trouble with defined named range
    By BRISBANEBOB in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 11-17-2012, 07:34 PM
  2. Named Range - looping through each cell
    By leshka_uk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-12-2012, 06:16 AM
  3. Looping in a user defined Range of Cells
    By dhatul in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 06-03-2011, 01:52 PM
  4. Looping a Named Range
    By Paluee in forum Excel General
    Replies: 6
    Last Post: 02-25-2010, 03:18 AM
  5. [SOLVED] Looping: Selecting elements from a named range to change calcs
    By Philip J Smith in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-11-2006, 12:25 PM

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