fhzhkunming
New Member
- Joined
- Mar 4, 2021
- Messages
- 30
- Office Version
-
- 365
- Platform
-
- Windows
Hi Folks,
I have a simple situation but I couldn't make it working.
I want to hide Rows 29-31 if D28 = "Yes" (Fig.1), and want to hide only Row 31 if D28 ="No" and D29 = "Number" (Fig. 2). In other words, if D28 = "Yes", Rows 29-31 are empty (Actually contents in these rows were invisible by conditional formatting); if D28 = "No" and D29 = "Number", only Row 31 is empty row (contents invisible). BTW, values of D28 and D29 were automatically copied from another sheet. I want this hide/unhide event to be automatically triggered.
Below is my code. Could anyone please help me out?
Thanks in advance.
Frank
I have a simple situation but I couldn't make it working.
I want to hide Rows 29-31 if D28 = "Yes" (Fig.1), and want to hide only Row 31 if D28 ="No" and D29 = "Number" (Fig. 2). In other words, if D28 = "Yes", Rows 29-31 are empty (Actually contents in these rows were invisible by conditional formatting); if D28 = "No" and D29 = "Number", only Row 31 is empty row (contents invisible). BTW, values of D28 and D29 were automatically copied from another sheet. I want this hide/unhide event to be automatically triggered.
Below is my code. Could anyone please help me out?
Thanks in advance.
Frank
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'MsgBox "Changed: " & Target.Address
Application.EnableEvents = False 'pervent triggering another change event
If Not Intersect(Target, Range("D28")) Is Nothing Then
If Range("D28").Value = "Yes" Then
Range("D29:D31").EntireRow.Hidden = True
ElseIf Range("D28").Value = "No" And Range("D29").Value = "Number" Then
Range("D31").EntireRow.Hidden = True
Else
Range("D29:D31").EntireRow.Hidden = False
End If
End If
Application.EnableEvents = True 're-enable events in the end
End Sub