+ Reply to Thread
Results 1 to 12 of 12

Include/Exclude certain sheets in loop

  1. #1
    Forum Contributor
    Join Date
    01-06-2012
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    165

    Include/Exclude certain sheets in loop

    Hi,

    I have a code that copy & pastes values in chosen columns in every sheet in the workbook.

    Please Login or Register  to view this content.
    Is it possible to exclude specific sheets, or instruct to only loop through specific sheets?

    For example if I just wanted it to run through sheet2 & sheet3 only.

    Thanks
    Last edited by BPSJACK; 10-07-2015 at 10:20 AM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    2013 on Win10 (desktop), 2007 on Win10 (notebook)
    Posts
    8,097

    Re: Include/Exclude certain sheets in loop

    Hi, BPSJACK,

    either use an array to hold the sheets to include/exclude or maybe use a Select Case:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Last edited by HaHoBe; 10-06-2015 at 06:55 AM. Reason: code correction
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    01-06-2012
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    165

    Re: Include/Exclude certain sheets in loop

    Thanks for the suggestion, I'm getting the following error when I try to run this one:

    "Compile Error: Invalid next control variable reference" on the "Next my" line.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    2013 on Win10 (desktop), 2007 on Win10 (notebook)
    Posts
    8,097

    Re: Include/Exclude certain sheets in loop

    Hi, BPSJACK,

    sorry, my fault, I didnīt substitute all my with ws. Code should look loke
    Please Login or Register  to view this content.
    Ciao,
    Holger

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Include/Exclude certain sheets in loop

    If you only want to exclude a few, maybe:

    Please Login or Register  to view this content.

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    2013 on Win10 (desktop), 2007 on Win10 (notebook)
    Posts
    8,097

    Re: Include/Exclude certain sheets in loop

    Hi, John,

    thereīs an End With missing in your code, and the Next my stands at th wrong position. And I doubt itīs a good idea to run the commeand for whole columns.

    Ciao,
    Holger

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,646

    Re: Include/Exclude certain sheets in loop

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.



  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Include/Exclude certain sheets in loop

    @ Ciao - Good catch. Wrote it too fast. My mistake

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    01-06-2012
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    165

    Re: Include/Exclude certain sheets in loop

    Thanks guys, however both solutions give me the error "Object doesn't support this property or method"

    Sub Freeze:
    on line "Select Case ws"

    Sub BPSJACKzz:
    on line "For Each my In ActiveSheet.Worksheets"

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Include/Exclude certain sheets in loop

    Oops, should be.

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    01-06-2012
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    165

    Re: Include/Exclude certain sheets in loop

    Woohoo! They both work now, thanks!!

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Include/Exclude certain sheets in loop

    You're welcome. Glad to help out and thanks for the feedback.

+ 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] Include 2 sheets in code loop?
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-19-2013, 04:21 PM
  2. Set filter to EXCLUDE values rather than include them
    By Uther_d_dragon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-21-2013, 10:54 AM
  3. Replies: 0
    Last Post: 06-06-2006, 02:15 PM
  4. Replies: 1
    Last Post: 06-06-2006, 10:30 AM
  5. [SOLVED] Comparing Data Need to Include & Exclude
    By in forum Excel General
    Replies: 1
    Last Post: 06-06-2006, 09:10 AM
  6. [SOLVED] Comparing Data Need to Include & Exclude
    By in forum Excel General
    Replies: 1
    Last Post: 06-05-2006, 03:40 PM
  7. [SOLVED] Comparing Data Need to Include & Exclude
    By in forum Excel General
    Replies: 0
    Last Post: 06-05-2006, 03: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