I Have the following code in my "Input" worksheet and every time cell D7 changes the sheet should unhide rows 11 through 26, and then depending if cell H for the row is blank, as a result of the change to D7, it should hide that row and all the rows below it. I have similar code in another worksheet that works perfectly, but here for some reason, the code is behaving erratically (sometimes it will hide rows, sometimes not).
Any suggestions would be appreciated.
Here is the code that is in the worksheet
Any suggestions would be appreciated.
Here is the code that is in the worksheet
VBA Code:
Option Explicit
Private Sub worksheet_change(ByVal target As Range)
Dim MyTarget As Range
Set MyTarget = Range("d7")
If Not Intersect(target, MyTarget) Is Nothing Then
Application.EnableEvents = False
ActiveSheet.Unprotect
Rows("11:26").EntireRow.Hidden = False
If [h11] = "" Then
Range("f11:f26").ClearContents
Rows("11:26").EntireRow.Hidden = True
ElseIf [h12] = "" Then
Range("f12:f26").ClearContents
Rows("12:26").EntireRow.Hidden = True
ElseIf [h13] = "" Then
Range("f13:f26").ClearContents
Rows("13:26").EntireRow.Hidden = True
ElseIf [h14] = "" Then
Range("f14:f26").ClearContents
Rows("14:26").EntireRow.Hidden = True
ElseIf [h15] = "" Then
Range("f15:f26").ClearContents
Rows("15:26").EntireRow.Hidden = True
ElseIf [h16] = "" Then
Range("f16:f26").ClearContents
Rows("16:26").EntireRow.Hidden = True
ElseIf [h17] = "" Then
Range("f17:f26").ClearContents
Rows("17:26").EntireRow.Hidden = True
ElseIf [h18] = "" Then
Range("f18:f26").ClearContents
Rows("18:26").EntireRow.Hidden = True
ElseIf [h19] = "" Then
Range("f19:f26").ClearContents
Rows("19:26").EntireRow.Hidden = True
ElseIf [h20] = "" Then
Range("f20:f26").ClearContents
Rows("20:26").EntireRow.Hidden = True
ElseIf [h21] = "" Then
Range("f21:f26").ClearContents
Rows("21:26").EntireRow.Hidden = True
ElseIf [h22] = "" Then
Range("f22:f26").ClearContents
Rows("22:26").EntireRow.Hidden = True
ElseIf [h23] = "" Then
Range("f23:f26").ClearContents
Rows("23:26").EntireRow.Hidden = True
ElseIf [h24] = "" Then
Range("f24:f26").ClearContents
Rows("24:26").EntireRow.Hidden = True
ElseIf [h25] = "" Then
Range("f25:f26").ClearContents
Rows("25:26").EntireRow.Hidden = True
ElseIf [h26] = "" Then
Range("f26:f26").ClearContents
Rows("26:26").EntireRow.Hidden = True
End If
Application.EnableEvents = False
End If
ActiveSheet.Protect
End Sub