Hide a row if a selected cell has a specific text.

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Hide a row if a selected cell has a specific text.

Post by ABabeNChrist »

What I’m trying to achieve is a toggle effect so that when the word “Blank” is selected from a data validation dropdown located on worksheet “Conclusion” in cell A7, It would then hide rows 5 and 6 and would also EntireRow.AutoFit A7, if another selection was made or cell left empty it would then unhide rows 5 and 6
I was trying something like this, but of course not right.

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim oCell As Range
    If Not Intersect(Target, Range("A5:A7")) Is Nothing Then
        For Each oCell In Intersect(Target, Range("A5:A20"))
            Application.ScreenUpdating = False
            Sheets("Conclusion").Range("A5:A6").EntireRow.Hidden = _
            (Application.CountA(Sheets("Conclusion").Range("A7")) = "Blank")
            'Sheets("Conclusion").Range("A7").EntireRow.AutoFit
            Application.ScreenUpdating = True
        Next oCell
    End If
End Sub

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Hide a row if a selected cell has a specific text.

Post by HansV »

Does this do what you want?

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A7")) Is Nothing Then
        Application.ScreenUpdating = False
        Range("A5:A6").EntireRow.Hidden = (Range("A7") = "Blank")
        Range("A7").EntireRow.AutoFit
        Application.ScreenUpdating = True
    End If
End Sub
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Hide a row if a selected cell has a specific text.

Post by ABabeNChrist »

PERFECT
Thank you Hans
:thankyou: