Clara Monspiette
Clara Monspiette

Reputation: 69

Unhide block of four rows without currentStage

I'm a beginner in coding and specially with VBA. I have an Excel document on which several rows are hidden. I need to unhide the row 34:37, 42:45, 50:53, 58:61, one block of four rows at a time, until they are all unhidden. I have a button made out of a shape.

For now, I have a currentStage function applied to the code, but it's counterproductive, since I don't want the code to hide rows, only unhide.

Here's the code for now :

Sub UnhideObjectives()
Static currentStage As Integer

    With ActiveSheet
        .Rows("34:37").EntireRow.Hidden = False
        .Rows("42:45").EntireRow.Hidden = (currentStage < 1)
        .Rows("50:53").EntireRow.Hidden = (currentStage < 2)
    End With

currentStage = (currentStage + 1) Mod 3
End Sub

Thank you.

Upvotes: 0

Views: 38

Answers (1)

Tim Williams
Tim Williams

Reputation: 166366

Unhide all rows in one operation:

Sub UnhideObjectives()
    ActiveSheet.range("A34:A37,A42:A45,A50:A53").EntireRow.Hidden = False
End Sub

Edit: OK I see what you mean

Sub UnhideObjectives()
    Dim rng As Range
    For Each rng In ActiveSheet.Range("A34:A37,A42:A45,A50:A53").Areas
        If rng.EntireRow.Hidden Then     'is this block hidden?
            rng.EntireRow.Hidden = False 'unhide
            Exit For                     '...and stop looping
        End If
    Next rng
End Sub

Upvotes: 0

Related Questions