+ Reply to Thread
Results 1 to 8 of 8

Avoid "Selecting" sheet in a For Next loop

  1. #1
    Registered User
    Join Date
    09-28-2019
    Location
    Chicago, IL
    MS-Off Ver
    2016
    Posts
    9

    Avoid "Selecting" sheet in a For Next loop

    Hi,

    I'd like to avoid screen flashing in my macro so I set sheets that are created by the subroutine to be hidden. Is there a way the .Select line (bolded below) can be re-written to avoid having the sheet be selected?

    Please Login or Register  to view this content.
    Last edited by keyboardqueen; 09-28-2020 at 06:33 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    36,279

    Re: Avoid "Selecting" sheet in a For Next loop

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional.)



    But, to be going on with, try ...

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Excel Aid

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,450

    Re: Avoid "Selecting" sheet in a For Next loop

    Please Login or Register  to view this content.


    I don't know why you are using a loop to do this.

    Use the Macro recorder to record you entering a formula in F1 to return the correct value. Paste that formula instead of ?????????????? below

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 09-28-2020 at 06:35 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Registered User
    Join Date
    09-28-2019
    Location
    Chicago, IL
    MS-Off Ver
    2016
    Posts
    9

    Re: Avoid "Selecting" sheet in a For Next loop

    Thanks mehmetcik and TMS

    Might be helpful if I share a bit more code. Running into an error that says "Compile Error - End If without block If". Do you know why this may be based on the below?

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-28-2019
    Location
    Chicago, IL
    MS-Off Ver
    2016
    Posts
    9

    Re: Avoid "Selecting" sheet in a For Next loop

    I've been learning how to write macros on my own now since October 2019 but am no expert at all yet (as you can probably tell). As a result, I sometimes will inevitably write something not as elegantly as some of you experts out there! I can work on implementing the above suggestion, mehmetcik. Thank you.

    Would still like to figure out why I'm getting the Compile Error above, however. Thanks in advance.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    36,279

    Re: Avoid "Selecting" sheet in a For Next loop

    If you want to use the loop, you need to look at the code in detail. Notice With ... End With and also the dots ( . ) in front of Range

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    36,279

    Re: Avoid "Selecting" sheet in a For Next loop

    This will fail:
    Please Login or Register  to view this content.
    because you can't select a cell on a hidden sheet.

  8. #8
    Registered User
    Join Date
    09-28-2019
    Location
    Chicago, IL
    MS-Off Ver
    2016
    Posts
    9

    Re: Avoid "Selecting" sheet in a For Next loop

    Aha, I see! Thanks for pointing that out - kind of embarrassing I didn't catch that.

    So is there a way to Dim this additional 'select' part out?

    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] syntax error in an "and" in "if" statement in a "for" loop
    By MaartenRo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-22-2020, 08:03 PM
  2. [SOLVED] Copy cells from range "C3" to "F3" with loop and blank field
    By masterm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-16-2015, 01:03 PM
  3. Lookup Number on "Summary" Sheet and Loop Through All Worksheets
    By Branbran10 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-05-2015, 04:28 PM
  4. Replies: 2
    Last Post: 01-15-2015, 04:45 PM
  5. Solution to populate cell with "X" by selecting "R"
    By nirola in forum Excel General
    Replies: 4
    Last Post: 11-17-2012, 10:15 AM
  6. Missing Chart When Selecting "As new sheet"
    By BNR_1 in forum Excel General
    Replies: 4
    Last Post: 01-30-2010, 02:00 PM
  7. [SOLVED] ? doing IF(N8="pilot",(AB8+.05) but how do I avoid the "false" value for nonmatching???
    By _Bigred in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 03-09-2005, 01:06 PM

Tags for this Thread

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