+ Reply to Thread
Results 1 to 5 of 5

Having trouble looping through sheets

  1. #1
    Registered User
    Join Date
    04-03-2014
    Location
    Woodbury, GA
    MS-Off Ver
    Excel 2010 and Excel 2013
    Posts
    37

    Having trouble looping through sheets

    I need to loop through the sheets in my workbook and alter Cell (1, 1). That's it. It's should be simple, but I can't get the code below to run past whatever sheet happens to be active at that moment. Any ideas why this might be?

    Here's my code snippet...
    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Having trouble looping through sheets

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    04-03-2014
    Location
    Woodbury, GA
    MS-Off Ver
    Excel 2010 and Excel 2013
    Posts
    37

    Re: Having trouble looping through sheets

    Quote Originally Posted by Norie View Post
    Try this.
    Please Login or Register  to view this content.
    It works! Thank you.

    If you have time, could you explain why my code didn't work as intended?

  4. #4
    Registered User
    Join Date
    04-03-2014
    Location
    Woodbury, GA
    MS-Off Ver
    Excel 2010 and Excel 2013
    Posts
    37

    Re: Having trouble looping through sheets

    Hmmm, though the above script works in that specific instance, I can't seem to get the loop to work with a more complex script such as that below...
    Please Login or Register  to view this content.
    I tried a dirtier way by importing the individual sheets names into an array and then looping through the array and selecting the name of the sheet that corresponds to the respective array index, but this give a runtime error '9' where the subscript is out of range. I can't figure out why.

    Here's that code...
    Please Login or Register  to view this content.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Having trouble looping through sheets

    In your code Columns and Rows don't reference a specific sheet, so they refer to the active sheet.

    What you need is a With statement and a couple of dots.
    Please Login or Register  to view this content.

+ 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 looping through column with data qualifier
    By fredderf81 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-27-2014, 03:18 PM
  2. [SOLVED] Trouble Looping Multiple Column Arrays
    By D.L. in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2012, 03:32 AM
  3. [SOLVED] Trouble Looping Macro
    By zhb12810 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-17-2012, 02:09 PM
  4. Trouble with looping through worksheets
    By eonizuka in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-05-2010, 09:08 PM
  5. [SOLVED] Trouble with looping
    By Rbp9ad in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-07-2005, 09:05 PM

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