Excel VBA: Hide Rows or Delete Cells with Multiple Text Values
Question details
Find three unwanted text values without regard to letter case and either hide their rows or delete the matching cells.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A user wants to process unwanted values in a worksheet column and understand how AutoFilter identifies its target column.
- Observed behavior
- The desired result is to hide rows containing the specified values or delete matching cells while shifting the remaining cells upward.
Identify the column and data rows to process, then replace Word1, Word2, and Word3 in the macro with your unwanted values. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if you need to retain the macro, and enable macros only for trusted files.
Hide rows that contain any of three text values
Use this reversible approach when you want to keep the data but remove matching rows from view.
In Excel, open the target workbook, press Alt+F11, and select Insert > Module.
Paste this code into the module. It checks Y18:Y1000 on the active sheet and ignores letter case: Sub HideUnwantedRows() Dim cell As Range For Each cell In ActiveSheet.Range("Y18:Y1000") If Not IsError(cell.Value) Then Select Case UCase$(CStr(cell.Value)) Case "WORD1", "WORD2", "WORD3" cell.EntireRow.Hidden = True End Select End If Next cell End Sub
Replace the range and the three uppercase values in the code. Activate the intended worksheet, open Developer > Macros, select HideUnwantedRows, and choose Run.

Delete matching cells and shift the column upward
Use this method when you want to remove the matching cells rather than hide their rows.
Review and Filter Spreadsheet Data with WPS Office
WPS Office is a free, lightweight alternative for working with spreadsheets in a familiar interface. Open compatible Excel files and use spreadsheet filters to review unwanted values as you move between office suites. Excel VBA support and macro behavior can vary by WPS version, so test macros separately.

Frequently Asked Questions
What does the AutoFilter Field parameter mean?
Field is the column position within the filter range, not a worksheet row number. For example, if the filter range is X17:Y1000, Field:=2 refers to column Y.
How do these macros ignore letter case?
They convert each cell value to uppercase with UCase$ before comparing it with the uppercase values in Select Case. Enter your replacement values in uppercase as well.
Why does the deletion macro loop backward?
Deleting a cell shifts the cells below it upward. A backward loop starts at the bottom so those shifts do not cause unprocessed matches to be skipped.
Will deleting matching cells remove the entire row?
No. Delete Shift:=xlUp removes only the matching cell and shifts cells below it in the same column. Use the hide-rows macro if the rest of each row must stay aligned.




