+ Reply to Thread
Results 1 to 5 of 5

loop through all sheets in a list

  1. #1
    Registered User
    Join Date
    11-14-2006
    Posts
    25

    loop through all sheets in a list

    hey guys, I am at my wits end trying to play with arrays and whatnot... what I want to do in simple terms is create a loop that runs code through sheets that are listed in a worksheet. For example....

    Workbook.xls has the following worksheets:

    Worksheet1
    Worksheet2
    Worksheet3
    Worksheet4
    Worksheet5
    Worksheet6
    Worksheet7
    Worksheet8
    Worksheet9
    Worksheet10

    Worksheet 10 has these values in Range A1:A6
    A1: "Worksheet2"
    A2: "Worksheet4"
    A3: "Worksheet5"
    A4: "Worksheet6"
    A5: "Worksheet7"
    A6: "Worksheet9"

    I have a macro I want to run on the worksheets listed in Worksheet10, the reason being is that worksheets are constantly added that need the code run in them. I want to avoid having to go into the code every time I want to add a new worksheet to run in the macro.

    What I was trying to do is create a dynamic array that counts the # of items in worksheet 10 and dims the array to that size. Then it would populate the array with the values from the list. Last it would loop the code through all worksheets in that dynamic array.

    Anyone help me please?

    Thanks,
    Kareem

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Does this help

    VBA Noob
    Attached Files Attached Files
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    11-14-2006
    Posts
    25
    It's a step in the right direction, however i'd rather not activate any sheets to work on it. I'd like it all to be vba coded. But if it must come to it then activating sheets will have to do.

    - Kareem

    P.S. Anyone know how to do this with a dynamic array?

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Selecting the sheets was a demo.

    I did this because as far as I can see you didn't say what the code is needed for

    VBA Noob

  5. #5
    Registered User
    Join Date
    11-14-2006
    Posts
    25
    Here is the code that's going to run in the "selected" sheets:

    Please Login or Register  to view this content.
    What the code does is it goes down column "J" and changes the cells with formulas to what's in the code. then anything after the cell containing X in column J to a different formula.

+ 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