Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Automatically hide rows in Excel based on value per row Hi I have to develop an

ID: 3561097 • Letter: A

Question

Automatically hide rows in Excel based on value per row

Hi

I have to develop an excelsheet where a row is hidden automatically if the value in cell e is 1 and unhide the row automatically if the value in cell e is 2. And this has to work for all rows

An example:

Row 20, cell E20 = 1 -> automatically hide row

Row 21, cell E21 = 2 -> automatically unhide row

Row 22, cell E22 = 2 -> automatically unhide row

etc.

The values in column E change regularly automatically based on other information in the excelsheet (with an if formula in colume E). And then the row should hide or unhide automatically

Can you please help me?

Thanks a lot

Explanation / Answer

%R$ight click the sheet tab, view code and paste this code in. Close VB editor.#%&


Private Sub Worksheet_Calculate()
Dim LastRow As Long, c As Range
Application.EnableEvents = False
LastRow = Cells(Cells.Rows.Count, "E").End(xlUp).Row
On Error Resume Next
For Each c In Range("E1:E" & LastRow)
   If c.Value = 1 Then
        c.EntireRow.Hidden = True
    ElseIf c.Value = 2 Then
        c.EntireRow.Hidden = False
    End If
Next
On Error GoTo 0
Application.EnableEvents = True
End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote