VBA & Macro Problems

Excel VBA: Hide Rows or Delete Cells with Multiple Text Values

Aamir Naveed AkramAamir Naveed Akram Nov 22, 2026 868 views

Question details

Find three unwanted text values without regard to letter case and either hide their rows or delete the matching cells.

Hide Rows or Delete Cells with Multiple Text Values in Excel VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, open the target workbook, press Alt+F11, and select Insert > Module.

2
Add the hide macro

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

3
Customize and run

Replace the range and the three uppercase values in the code. Activate the intended worksheet, open Developer > Macros, select HideUnwantedRows, and choose Run.

Hide rows that contain any of three text values
Unhide rows: To show hidden rows again, select the affected rows or the entire sheet, then choose Home > Format > Hide & Unhide > Unhide Rows. This may also reveal rows hidden for other reasons.
Free Microsoft Office alternative

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.

Filter spreadsheet columns to review unwanted valuesOpen and edit Microsoft Excel XLSX filesUse a familiar spreadsheet interfaceWork with a free, lightweight office suite
microsoft office alternative - wps office

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.