How to automatically hide rows based on data validation cell value from different sheet inn the same workbook

Anonymous
2024-01-23T16:58:12+00:00

Hello,

I'd like to hide a select number of rows on sheet 2(Civil Test) based of a drop down data validation cell value from sheet 1(Pre Con Checklist) and perform this several times within sheet 2(Civil Test) . The cell value from sheet 1 (Pre Con Checklist) is a drop down data validation cell with the only options being Y or N. If Y from cell (O53) on the Pre Con Checklist sheet is selected then I want a range of cells on sheet 2(Civil Test) to show. If N is selected or the cell is left blank, then I want the range of rows from sheet 2 to be hidden. I am able to do this if the Y or N selection is from the same sheet from the code below

***************************************************************

Private Sub Worksheet_Change(ByVal Target As Range)

''this line will Unhide all rows in the sheet

Rows("1:" & Rows.Count).EntireRow.Hidden = False

''''Your conditions as per criteria for cell A3

If Range("A3") = "N" Then

Rows("4:12").EntireRow.Hidden = True

Else

Rows("4:12").EntireRow.Hidden = False

End If

End Sub

**************************************************************

I was able to manipulate the code from the follow post of questions and answers. But I cannot figure out how to pull the Y/N option from a different sheet even though it is in the same workbook, and if the data validation option makes a different? Thank you!

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. HansV 462.4K Reputation points MVP Volunteer Moderator
    2024-01-23T18:16:25+00:00

    Try this:

    Private Sub Worksheet_Change(ByVal Target As Range)
        With Worksheets("Other Sheet") ' substitute the real name
            ''this line will Unhide all rows in the sheet
            .Cells.EntireRow.Hidden = False
            ''''Your conditions as per criteria for cell A3
            .Range("A4:A12").EntireRow.Hidden = (Range("A3") <> "Y")
        End With
    End Sub
    
    0 comments No comments
  2. Anonymous
    2024-01-23T20:28:45+00:00

    Hi Hans,

    Unfortunately this did not work. I updated my question with photos to hopefully get the correct response. Can you please take a look.

    0 comments No comments
  3. HansV 462.4K Reputation points MVP Volunteer Moderator
    2024-01-23T21:28:26+00:00

    Try changing A3 in the code to O53

    0 comments No comments
  4. Anonymous
    2024-01-23T21:41:21+00:00

    Hi Hans, The rows are still not hidden with the above code.

    0 comments No comments
  5. HansV 462.4K Reputation points MVP Volunteer Moderator
    2024-01-23T22:19:06+00:00

    Did you change the value of O53?

    0 comments No comments