Macors to unhide cells

nathans excel

New Member
Joined
Nov 15, 2017
Messages
3
Good day,

I am new to macros but a quick learner!! I have a row of cells 11:16 that I have hidden ... I would like to add some VBA to a command button so that when it is clicked it unhides 2 rows per click ...

Click once: 11:12 unhidden
click a second time: 13:14 unhidden
3rd time 15:16 unhidden

Ive googled plenty of code to unhide the entire range which is fine ... but also not what I am looking for

Any help is appreciated, Nathan
Excel 2013
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi, welcome to MrExcel
Try this
Code:
Sub Unhiderws()

    Select Case True
        Case Rows(12).Hidden
            Rows("11:12").Hidden = False
        Case Rows(14).Hidden
            Rows("13:14").Hidden = False
        Case Rows(16).Hidden
            Rows("15:16").Hidden = False
    End Select

End Sub
 
Upvote 0
You can attach this to a Form Controls button and each time you click the button, it will search for hidden rows and unhide the first two of any group of rows that are found each time button is clicked, so long as the rows are contiguous.

Code:
Sub t()
Dim r As Range, rw As Range
For Each r In ActiveSheet.Rows
    If r.Hidden = True Then
        If rw Is Nothing Then
            Set rw = r
        Else
            Set rw = Union(rw, r)
        End If
    End If
Next
rw.Resize(2).EntireRow.Hidden = False
End Sub

For a qucker response time, you can change the 'Rows' on the For Each line to a specific ranged like 'Range("2:20")' to reduce the seach time.
 
Last edited:
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,873
Messages
6,127,442
Members
449,382
Latest member
DonnaRisso

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