pdharrison85
New Member
Hi guys
Any help would be gratefully accepted! I am trying to write VB code to hide my rows depending upon the value entered into a cell. There will be a value entered into a cell in my excel sheet (the value will be a whole number 1,2,3 or 4) then depending upon this value I will want to hide 1,2 or 3 rows within the same sheet. I have written the code but I think it contains errors! Here is the code:
[pre]
[/pre]
Any help would be gratefully accepted! I am trying to write VB code to hide my rows depending upon the value entered into a cell. There will be a value entered into a cell in my excel sheet (the value will be a whole number 1,2,3 or 4) then depending upon this value I will want to hide 1,2 or 3 rows within the same sheet. I have written the code but I think it contains errors! Here is the code:
[pre]
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' We only want to do something if the changed cell is D20
If Target.Address = "$D$20" Then
' Check it is a number
If IsNumeric(Target.Value) Then
' Check if its number 1
If (Target.Value) = "1" Then
Rows("22:24").EntireRow.Hidden = True
Else
Rows("22:24").EntireRow.Hidden = False
' Check if its number 2
If (Target.Value) = "2" Then
Rows("23:24").EntireRow.Hidden = True
Else
Rows("23:24").EntireRow.Hidden = False
' Check if its number 3
If (Target.Value) = "3" Then
Rows("24:24").EntireRow.Hidden = True
End If
End If
End If
End If
End If
End Sub