Vba to hide/unhide rows depending on cell value

neilcsmith1984

New Member
Joined
May 25, 2020
Messages
14
Office Version
  1. 2013
Platform
  1. Windows
Hi,

I have created the below VBA to hide rows depending on the value in A99, which works fine.
However, when the value in cell A99 changes to a higher value it hides the required rows, but does not unhide the rows above.

Is there any way to adjust the formula, to unhide the previous rows

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
With Sheets("Overview")


Thanks

If Target.Address = "$A$99" Then
If Target.Value = 1 Then Rows("102:119").EntireRow.Hidden = True
If Target.Value = 2 Then Rows("103:119").EntireRow.Hidden = True
If Target.Value = 3 Then Rows("104:119").EntireRow.Hidden = True
If Target.Value = 4 Then Rows("105:119").EntireRow.Hidden = True
If Target.Value = 5 Then Rows("106:119").EntireRow.Hidden = True
If Target.Value = 6 Then Rows("107:119").EntireRow.Hidden = True
If Target.Value = 7 Then Rows("108:119").EntireRow.Hidden = True
If Target.Value = 8 Then Rows("109:119").EntireRow.Hidden = True
If Target.Value = 9 Then Rows("110:119").EntireRow.Hidden = True
If Target.Value = 10 Then Rows("111:119").EntireRow.Hidden = True
If Target.Value = 11 Then Rows("112:119").EntireRow.Hidden = True
If Target.Value = 12 Then Rows("113:119").EntireRow.Hidden = True
If Target.Value = 13 Then Rows("114:119").EntireRow.Hidden = True
If Target.Value = 14 Then Rows("115:119").EntireRow.Hidden = True
If Target.Value = 15 Then Rows("116:119").EntireRow.Hidden = True
If Target.Value = 16 Then Rows("117:119").EntireRow.Hidden = True
If Target.Value = 17 Then Rows("118:119").EntireRow.Hidden = True
If Target.Value = 18 Then Rows("119:119").EntireRow.Hidden = True
If Target.Value > 18 Then Rows("102:119").EntireRow.Hidden = False
End If
End With
End Sub
 
You could use a calculate event, instead of the change event, but that will trigger whenever any cell on the sheet recalculates.
Or you could put some code in the combo to hide the rows.
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,214,878
Messages
6,122,062
Members
449,064
Latest member
scottdog129

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