VBA & Macro Problems

How to Automatically Hide an Excel Row When Four Cells Are Blank

Adam DavisAdam Davis Nov 10, 2026 869 views

Question details

The user needs to automatically hide a row in an Excel spreadsheet if four specific cells within that row are completely empty.

How to Automatically Hide an Excel Row When Four Cells Are Blank
Product
Excel
Device & OS
Windows / Mac
Scenario
Organizing and cleaning up a dataset where rows with specific missing data across four columns need to be temporarily removed from view without deleting them.
Observed behavior
Excel formulas cannot directly alter row visibility. Rows remain visible regardless of cell contents unless manually hidden, filtered out with a helper column, or managed via VBA or Office Scripts.
Before you start

If you choose to use the VBA method, ensure you save your workbook as an Excel Macro-Enabled Workbook (.xlsm) to prevent losing your code when you close the file.

Solution 1Recommended

Use a Helper Column and Filter

A simple, formula-based approach that does not require coding. You create a helper column to identify rows with four blank cells and then use Excel's built-in filter to hide them.

Since standard Excel formulas cannot physically hide rows, we can use a helper formula to flag the rows we want to hide. The COUNTA function counts cells that are not empty, making it perfect for this scenario.

1
Add the helper formula

Insert a new column next to your data. In the first row of your data (e.g., F2), enter the formula =COUNTA(B2:E2)=0 (assuming B2, C2, D2, and E2 are the four cells you are checking).

2
Copy the formula down

Click the fill handle in the bottom-right corner of cell F2 and drag it down to apply the formula to all relevant rows. The formula will return TRUE if all four cells are blank, and FALSE if any cell contains data.

3
Apply a filter

Select your entire data range, go to the 'Data' tab on the ribbon, and click 'Filter'.

4
Hide the blank rows

Click the filter dropdown arrow in your helper column header. Uncheck 'TRUE' and click 'OK'. All rows where the four cells are blank will now be hidden.

Use a Helper Column and Filter
Dynamic Updates: If you update the data in those cells later, simply re-apply the filter to update which rows are hidden or visible.
Powerful Data Management

Easily Filter or Run VBA Macros in WPS Office

WPS Spreadsheet fully supports Excel formulas, advanced filtering, and VBA macros, allowing you to easily hide rows with blank cells using either method. It provides a familiar interface to seamlessly manage complex datasets.

  1. 1. Open your file in WPS: Launch WPS Spreadsheet and open your existing Excel workbook.
  2. 2. Apply the helper formula: Create a new column and input the =COUNTA() formula to flag rows with empty cells.
  3. 3. Filter the rows: Navigate to the Data tab, click Filter, and deselect the rows marked as blank.
  4. 4. Utilize VBA: Alternatively, go to the Developer tab to open the VBA editor and execute your row-hiding macro directly.
Fully compatible with Microsoft Excel formats (.xlsx, .xlsm).Built-in support for advanced filtering and VBA macros.Familiar user interface for seamless workflow migration.Lightweight, fast, and completely free to use.
microsoft office alternative - wps office

Frequently Asked Questions

Can I use conditional formatting to hide rows with blank cells?

No, conditional formatting can only change the visual appearance of cells (such as changing the font color to match the background), but it cannot physically hide the row or change the row height to zero. You must use filters or VBA.

Will the rows unhide automatically if I add data to the blank cells later?

If you used the helper column and filter method, you need to click 'Reapply' in the Data tab. If you used a standard VBA macro, you must run the macro again to unhide the rows. However, you can use the Worksheet_Change event in VBA to trigger the hiding/unhiding automatically when cell values change.

Does the COUNTA formula work if my cells contain spaces instead of being truly blank?

No, the COUNTA function counts cells with any content, including hidden characters or spaces. To ensure true blanks are counted accurately, you might need to use the COUNTBLANK function or a combination of SUMPRODUCT and TRIM.

Can I use Office Scripts instead of VBA?

Yes, if you are using Excel on the Web or a Microsoft 365 desktop version that supports it. Office Scripts use TypeScript to automate tasks and can be used to hide rows when cells are empty, providing an alternative to VBA that works within web browsers.