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
 

Learning To Excel

Board Regular
Joined
Jul 22, 2015
Messages
199
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
 

Forum statistics

Threads
1,081,575
Messages
5,359,723
Members
400,545
Latest member
Damntheman30

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top