Selectively set row height (or hide / unhide rows) using a macro

BryanSergeant

New Member
Joined
Jan 6, 2015
Messages
2
Hi Folks,

I’m trying to write a macro to run down an Excel sheet and selectively, based on a parameter, set the row height to zero or 15.
It could be expressed as:
- For Rows 1 to 500
- If the value of the cell in column A for a row is 0, then set that row height to 0
- If the value of the cell in column A for a row is 1, then set that row height to 15

I’ve created a macros in the past but am pretty lightweight at it… so would greatly appreciate any help :-)

Thanks, in advance,
Bryan
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Welcome to MrExcel

Does this work for you?

Code:
Sub Test()
    Dim i As Long
    With ActiveSheet
        For i = 1 To .Range("A" & .Rows.Count).End(xlUp).Row
            If .Range("A" & i).Value = 0 Then
                .Rows(i).EntireRow.RowHeight = 0
            ElseIf .Range("A" & i).Value = 1 Then
                .Rows(i).EntireRow.RowHeight = 15
            End If
        Next i
    End With
End Sub
 
Upvote 0
Hi Andrew,

Brilliant!!!!
It works perfectly.
You wonderful chap!!

Thank you so much for solving my headache.
Very very grateful... thank you.

Hope I can help you some day.

Best wishes,
Bryan



Welcome to MrExcel

Does this work for you?

Code:
Sub Test()
    Dim i As Long
    With ActiveSheet
        For i = 1 To .Range("A" & .Rows.Count).End(xlUp).Row
            If .Range("A" & i).Value = 0 Then
                .Rows(i).EntireRow.RowHeight = 0
            ElseIf .Range("A" & i).Value = 1 Then
                .Rows(i).EntireRow.RowHeight = 15
            End If
        Next i
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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