Share via

Hide a row if the cell contains “Yes”

Anonymous
2021-02-03T07:24:33+00:00

Hello Community

I would like a function (or maybe VB?) to help with the following please.

If the word “Yes” is in a cell in Column A then hide the corresponding row.

eg “Yes” is in A3, hide row 3.  ‘Yes’ is in cell A5, hide row 5

A4 is blank so the row is displaying, but at a later time ‘Yes’ may be entered into A4 so row 4 would be hidden

I’m using the current version of Excel

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

Answer accepted by question author

Anonymous
2021-02-03T08:37:14+00:00

Hi NZAnn,

Thank you for querying in this forum.

From your description, it seems that you want to hide the related rows it the cells contains Yes.

If my understanding is right, you can use the VBA code below:

Sub HideRows()

Dim cell As Range

For Each cell InActiveWorkbook.ActiveSheet.Columns("A").Cells

If cell.Value ="Yes" Then

cell.EntireRow.Hidden = True

End If

Next cell

End Sub

We have tested it on our side, and we created a new workbook > typed Yes and No in column A, as shown below:

Then clicked Developer > Visual Basic > Inserted Module, run VBA code above, as shown below:

If the scenario above is not consistent with yours, you can also post back and provide more details about your requirement.

Best Regards,

Sukie

Was this answer helpful?

3 people found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2021-02-03T09:12:01+00:00

    Hello Sukie

    This is perfect for my requirements. Thank you so much, you’re a star!

    Was this answer helpful?

    0 comments No comments