how to hide the entire row on specific cell value

Copper Contributor

I am creating excel template for a report in Oracle HCM. I need to hide any row that are coming with a specific cell values. Could this be accomplished with the template?

1 Reply

@skolawol05 

 

Sub HideRowsBasedOnCellValue()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim cell As Range
    Dim hideValue As String
    
    ' Set the worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name
    
    ' Define the cell value to hide rows
    hideValue = "Hide" ' Change "Hide" to your specific cell value
    
    ' Find the last row with data in column A
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    
    ' Loop through each row
    For Each cell In ws.Range("A1:A" & lastRow)
        ' Check if the cell value matches the value to hide rows
        If cell.Value = hideValue Then
            ' Hide the entire row
            cell.EntireRow.Hidden = True
        End If
    Next cell
End Sub

VBA Code ist untested, please backup your file.