+ Reply to Thread
Results 1 to 10 of 10

VBA Loop

  1. #1
    Registered User
    Join Date
    04-22-2014
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    23

    VBA Loop

    I have the code written for one worksheet but how do I write it so that it will loop through all of the worksheets? With the exception of one worksheet. I want to focus on the name of the worksheet so that my macro doesn't run there. Any help at all would be greatly appreciated!

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Loop

    Like this:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

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

    Re: VBA Loop

    Can you post the code you have?
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    04-22-2014
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: VBA Loop

    Dim ws As Worksheet
    For Each ws In Worksheets
    If ws.Name = "Tested Party" Then GoTo GetNext
    Range("G8").Select
    ActiveCell.FormulaR1C1 = "2014"
    GetNext: Next: End Sub

  5. #5
    Registered User
    Join Date
    06-12-2015
    Location
    Maryland, USA
    MS-Off Ver
    2010
    Posts
    83

    Re: VBA Loop

    I would use:

    Please Login or Register  to view this content.
    that way no need to use the GoTo instruction

  6. #6
    Registered User
    Join Date
    04-22-2014
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: VBA Loop

    Dim ws As Worksheet
    For Each ws In Worksheets
    If ws.Name = "Tested Party" Then GoTo GetNext
    Range("G8").Select
    ActiveCell.FormulaR1C1 = "2014"
    GetNext: Next: End Sub

  7. #7
    Registered User
    Join Date
    04-22-2014
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: VBA Loop

    JoeFoot,

    Thank you for the code, I think I'm close but it's still only running the macro in the sheet i'm currently in. How can I run the macro in every sheet except the sheet named "Tested Party"?

  8. #8
    Registered User
    Join Date
    06-12-2015
    Location
    Maryland, USA
    MS-Off Ver
    2010
    Posts
    83

    Re: VBA Loop

    you need to select the sheet at each iteration. This way the code runs on each sheet except "Tested Party"

    Please Login or Register  to view this content.

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

    Re: VBA Loop

    You don't need to select each sheet, and you don't need to select the cell either.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    04-22-2014
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: VBA Loop

    I got it! Thanks so much guys

+ 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. Loop through multiple files and call macros (but unable to loop)
    By ryanpetersen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-23-2014, 12:04 PM
  2. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  3. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM
  4. Replies: 0
    Last Post: 07-20-2010, 11:42 AM
  5. Loop a column on Sheet1 and loop a row on Sheet2 to find a match
    By johnnywinter in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-13-2009, 02:09 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