Unhide multiple groups of rows, one group at a time

Alaska_A

New Member
Joined
Jul 21, 2015
Messages
5
I am attempting to use one macro to unhide a select group of rows in a locked worksheet. I have a VBA code but it only unhides 1 row at a time, and the one who wrote it isn't around to fix it.

I am looking to make 1 button that when clicked, will unhide rows 110:130, then if pressed again will unhide rows 131:154 and so on.

This is the code I have been using:
Sub UnhideRows110_130()
Sheet1.Unprotect Password:="pass"
If Rows("130").Hidden = False Then MsgBox "No more rows available": Exit Sub
For ThsRw = 110 To 130
If Rows(ThsRw).Hidden = True Then
Rows(ThsRw).Hidden = False
Exit For
End If
Next ThsRw
Sheet1.Protect Password:="pass"
End Sub
Sub UnhideRows131_154()
Sheet1.Unprotect Password:="pass"
If Rows("153").Hidden = False Then MsgBox "No more rows available": Exit Sub
For ThsRw = 131 To 154
If Rows(ThsRw).Hidden = True Then
Rows(ThsRw).Hidden = False
Exit For
End If
Next ThsRw
Sheet1.Protect Password:="pass"
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
The following code matches the conditions from your previous code (If Rows(130).Hidden, If Rows(153).Hidden) but is a single macro that will unhide all of 110 - 130 if 130 is hidden, and unhide all of 131 - 154 if 153 is hidden. It seemed like you wanted it to happen in separate clicks, which is the purpose of (Sheet1.Protect Password:="pass" Exit Sub) existing inside the if statement. I'm not sure what you mean by "and so on" if the macro is intended to do more please specify. Here is the macro:

Code:
Sub UnhideRows()


Sheet1.Unprotect Password:="pass"


    If Rows(130).Hidden = True Then
        Range(Rows(110), Rows(130)).Hidden = False
        Sheet1.Protect Password:="pass"
        Exit Sub
    ElseIf Rows(153).Hidden = True Then
        Range(Rows(131), Rows(154)).Hidden = False
    Else
        MsgBox "All rows are already visible"
    End If
    
Sheet1.Protect Password:="pass"


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,195
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top