+ Reply to Thread
Results 1 to 10 of 10

assistance vba on clear contents on several sheets invalid next control variable referenc

  1. #1
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    assistance vba on clear contents on several sheets invalid next control variable referenc

    Hi All

    I have several sheets but I do not want to clear row 1 which are headers, the vba code is showing compile error invalid next control variable reference.

    Can anyone assist

    Please Login or Register  to view this content.

  2. #2
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: assistance vba on clear contents on several sheets invalid next control variable refe

    Try this:
    Please Login or Register  to view this content.
    OR:
    Please Login or Register  to view this content.
    sht is now an object of type WORKSHEET. The For...Each construct is only used with collection objects (in this case, the Sheets collection)
    Please click the Add Reputation star below any helpful posts, and if you have your answer, mark your thread as SOLVED (Thread Tools up top). Thanks!-Lee
    Last edited by leelnich; 05-23-2017 at 02:23 PM.

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: assistance vba on clear contents on several sheets invalid next control variable refe

    in the OP code, change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    Re: assistance vba on clear contents on several sheets invalid next control variable refe

    Still same invalid next control reference compile error message




    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    Re: assistance vba on clear contents on several sheets invalid next control variable refe

    thank you Mike

    working now

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    Re: assistance vba on clear contents on several sheets invalid next control variable refe

    Hi Leelnich

    Try your second option , working . but the first option giving me the invalid next control variable

    Could you post the whole code for the first option for me what going wrong on my side

  7. #7
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: assistance vba on clear contents on several sheets invalid next control variable refe

    Please Login or Register  to view this content.
    Actually, I was wrong about the For...Each construction. This works too:
    Please Login or Register  to view this content.
    Last edited by leelnich; 05-23-2017 at 03:12 PM.

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: assistance vba on clear contents on several sheets invalid next control variable refe

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    Re: assistance vba on clear contents on several sheets invalid next control variable refe

    leelnich

    Thank you for your solutions,codes working smartly

  10. #10
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: assistance vba on clear contents on several sheets invalid next control variable refe

    You're most welcome, and thank you 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] Invalid next control variable reference?
    By PDBartlett in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-09-2014, 09:29 AM
  2. invalid next control variable reference
    By stockgoblin42 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-03-2013, 05:08 PM
  3. invalid next control variable reference for looping
    By alienalvan in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-30-2013, 03:19 PM
  4. Compile Error: Invalid Next Control Variable Reference
    By mlegge04 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-25-2012, 02:38 PM
  5. [SOLVED] Invalid Next control variable reference
    By dslack in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-05-2012, 08:20 PM
  6. invalid next control variable reference
    By stevesunfold in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-17-2008, 08:09 PM
  7. Invalid Next Control Variable Reference
    By teresa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-31-2005, 08: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