Hiding rows

O

ordnance1

I need to be able to hide/unhide rows base upon a value.

If cell P5 has a value of 1, then hide rows 6,7,8 and 9
If cell P5 has a value of 2, then hide rows 7,8 and 9
If cell P5 has a value of 3, then hide rows 8 and 9
If cell P5 has a value of 4, then rows 6, 7, 8 and 9 would be visible

Would like to do this as a WorksheetChange event.
 
R

Rick Rothstein

Give this Change event code a try...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim N As Long
If Target.Address = "$P$5" Then
N = Target.Value
If N > 0 And N < 5 Then
Rows("6:9").Hidden = False
If N < 4 Then Rows((5 + N) & ":9").Hidden = True
End If
End If
End Sub

Rick (MVP - Excel)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top