+ Reply to Thread
Results 1 to 3 of 3

Looping with Hidden and Protected Sheets/Ranges

  1. #1
    ExcelMonkey
    Guest

    Looping with Hidden and Protected Sheets/Ranges

    I know I can hide sheets in excel. When I am looping through sheets using a
    For Next loop in VBA (using Sheets collection) will I ever run into issues
    with sheets that are hidden and or protected? That is, could I ever be in a
    situation where my For Next loop would fail due to hidden/protected sheets?

    I guess the same question extends to cell ranges. If I am looping through
    sheets and then cell ranges (For Each cell in .UsedRange) and lets say I am
    assessing formulas/data/text, will hidden row/columns and or protected cells
    cause errors in these sub loops?

    Thanks

  2. #2
    Jim Thomlinson
    Guest

    RE: Looping with Hidden and Protected Sheets/Ranges

    There is not a problem with the loops themselves. Just keep in mind that
    there are certain things you can not do with hidden or protected sheets. For
    example you can not select a hidden sheet so the following code may not
    work...

    dim wks as worksheet
    for each wks in worksheets
    wks.select ' will fail on hidden sheets
    next wks

    --
    HTH...

    Jim Thomlinson


    "ExcelMonkey" wrote:

    > I know I can hide sheets in excel. When I am looping through sheets using a
    > For Next loop in VBA (using Sheets collection) will I ever run into issues
    > with sheets that are hidden and or protected? That is, could I ever be in a
    > situation where my For Next loop would fail due to hidden/protected sheets?
    >
    > I guess the same question extends to cell ranges. If I am looping through
    > sheets and then cell ranges (For Each cell in .UsedRange) and lets say I am
    > assessing formulas/data/text, will hidden row/columns and or protected cells
    > cause errors in these sub loops?
    >
    > Thanks


  3. #3
    Tom Ogilvy
    Guest

    Re: Looping with Hidden and Protected Sheets/Ranges

    You can't select a hidden sheet. But if you don't try to select or
    activate, then hidden sheets shouldn't interfere with the loop structure
    itself.

    Looping through cells shouldn't be affected by whether they are in a hidden
    row or column. Actions you may perform on those cells or with those cells
    may have problems, but the best would just be to test the code.

    --
    Regards,
    Tom Ogilvy


    "ExcelMonkey" <ExcelMonkey@discussions.microsoft.com> wrote in message
    news:6862A612-71F7-4E78-9D15-F7EBE95B8C48@microsoft.com...
    > I know I can hide sheets in excel. When I am looping through sheets using

    a
    > For Next loop in VBA (using Sheets collection) will I ever run into issues
    > with sheets that are hidden and or protected? That is, could I ever be in

    a
    > situation where my For Next loop would fail due to hidden/protected

    sheets?
    >
    > I guess the same question extends to cell ranges. If I am looping through
    > sheets and then cell ranges (For Each cell in .UsedRange) and lets say I

    am
    > assessing formulas/data/text, will hidden row/columns and or protected

    cells
    > cause errors in these sub loops?
    >
    > Thanks




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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