+ Reply to Thread
Results 1 to 5 of 5

Loop through worksheets to unhide rows

Hybrid View

Guest Loop through worksheets to... 02-20-2006, 10:35 PM
Guest Re: Loop through worksheets... 02-20-2006, 10:45 PM
Guest Re: Loop through worksheets... 02-20-2006, 11:30 PM
Guest Re: Loop through worksheets... 02-20-2006, 11:35 PM
Guest Re: Loop through worksheets... 02-21-2006, 12:15 AM
  1. #1
    Punsterr
    Guest

    Loop through worksheets to unhide rows

    Hi all,

    I'm trying to write a sub where the user will click a box ("Hide Unused
    Rows in all Worksheets") and the macro will go through each worksheet
    in my workbook and will unhide all of the hidden rows. Both the
    workbook and each individual worksheet have protection - we'll assume
    both passwords are "password" for this example.

    Issues:

    1) The macro below runs, but it is not unhiding the rows.
    2) The way I've written it will check 200 rows in each worksheet. Is
    there an easy way for it to check only through the last active row on
    each worksheet?

    Sub UnhideAllRowsWorkbook()

    ' Unhides all rows throughout the workbook

    Application.ScreenUpdating = False
    ActiveWorkbook.Unprotect Password:="Password"
    Dim WS As Worksheet
    For Each WS In ThisWorkbook.Worksheets
    WS.Unprotect Password:="Password"
    Rows("1:200").EntireRow.Hidden = False
    WS.Protect Password:="Password",
    userinterfaceonly:=True, AllowFormattingCells:=True,
    AllowFormattingColumns:=True, AllowFormattingRows:=True
    WS.EnableSelection = xlNoRestrictions
    Next WS
    ActiveWorkbook.Protect Password:="Password", Structure:=True,
    Windows:=True
    Cells(1, 1).Select
    Application.ScreenUpdating = True
    MsgBox "All rows throughout the workbook are now visible.",
    vbOKOnly
    End Sub


  2. #2
    Tom Ogilvy
    Guest

    Re: Loop through worksheets to unhide rows



    Application.ScreenUpdating = False
    ActiveWorkbook.Unprotect Password:="Password"
    Dim WS As Worksheet
    For Each WS In ThisWorkbook.Worksheets
    WS.Unprotect Password:="Password"
    ' change made:
    ws.UserRange.EntireRow.Hidden = False
    WS.Protect Password:="Password",
    userinterfaceonly:=True, AllowFormattingCells:=True,
    AllowFormattingColumns:=True, AllowFormattingRows:=True
    WS.EnableSelection = xlNoRestrictions
    Next WS
    ActiveWorkbook.Protect Password:="Password", Structure:=True,
    Windows:=True
    Cells(1, 1).Select
    Application.ScreenUpdating = True
    MsgBox "All rows throughout the workbook are now visible.",
    vbOKOnly
    End Sub

    --
    Regards,
    Tom Ogilvy


    "Punsterr" <punsterr@hotmail.com> wrote in message
    news:1140489263.504187.118180@o13g2000cwo.googlegroups.com...
    > Hi all,
    >
    > I'm trying to write a sub where the user will click a box ("Hide Unused
    > Rows in all Worksheets") and the macro will go through each worksheet
    > in my workbook and will unhide all of the hidden rows. Both the
    > workbook and each individual worksheet have protection - we'll assume
    > both passwords are "password" for this example.
    >
    > Issues:
    >
    > 1) The macro below runs, but it is not unhiding the rows.
    > 2) The way I've written it will check 200 rows in each worksheet. Is
    > there an easy way for it to check only through the last active row on
    > each worksheet?
    >
    > Sub UnhideAllRowsWorkbook()
    >
    > ' Unhides all rows throughout the workbook
    >
    > Application.ScreenUpdating = False
    > ActiveWorkbook.Unprotect Password:="Password"
    > Dim WS As Worksheet
    > For Each WS In ThisWorkbook.Worksheets
    > WS.Unprotect Password:="Password"
    > Rows("1:200").EntireRow.Hidden = False
    > WS.Protect Password:="Password",
    > userinterfaceonly:=True, AllowFormattingCells:=True,
    > AllowFormattingColumns:=True, AllowFormattingRows:=True
    > WS.EnableSelection = xlNoRestrictions
    > Next WS
    > ActiveWorkbook.Protect Password:="Password", Structure:=True,
    > Windows:=True
    > Cells(1, 1).Select
    > Application.ScreenUpdating = True
    > MsgBox "All rows throughout the workbook are now visible.",
    > vbOKOnly
    > End Sub
    >




  3. #3
    Punsterr
    Guest

    Re: Loop through worksheets to unhide rows

    Tom,

    Thanks for your quick response. However, there appears to be an error
    with the change you suggested (ws.UserRange.EntireRow.Hidden = False).
    I get a compile error "method or data member not found."

    I also am still curious as to why my initial attempt didn't work (just
    unhiding all of rows 1-200 on each worksheet). The macro runs, it
    doesn't error out, but yet it doesn't unhide the rows. Is there an
    issue with it being called from another sub?


  4. #4
    Tom Ogilvy
    Guest

    Re: Loop through worksheets to unhide rows

    ws.UserRange.EntireRow.Hidden = False
    was a typo

    it should be

    ws.UsedRange.EntireRow.Hidden = False

    it didn't work for the same reason as your next post. The unqualified rows
    refered to the activesheet.

    --
    Regards,
    Tom Ogilvy

    "Punsterr" <punsterr@hotmail.com> wrote in message
    news:1140492414.515251.211520@z14g2000cwz.googlegroups.com...
    > Tom,
    >
    > Thanks for your quick response. However, there appears to be an error
    > with the change you suggested (ws.UserRange.EntireRow.Hidden = False).
    > I get a compile error "method or data member not found."
    >
    > I also am still curious as to why my initial attempt didn't work (just
    > unhiding all of rows 1-200 on each worksheet). The macro runs, it
    > doesn't error out, but yet it doesn't unhide the rows. Is there an
    > issue with it being called from another sub?
    >




  5. #5
    Punsterr
    Guest

    Re: Loop through worksheets to unhide rows

    Got it. Thanks a bunch!


+ 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