ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hiding rows (https://www.excelbanter.com/excel-programming/440838-hiding-rows.html)

ordnance1[_2_]

Hiding rows
 
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.

Rick Rothstein

Hiding rows
 
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)


"ordnance1" wrote in message
...
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.




All times are GMT +1. The time now is 09:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com