How to Automatically Hide an Excel Row When Four Cells Are Blank
Question details
The user needs to automatically hide a row in an Excel spreadsheet if four specific cells within that row are completely empty.

- 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.
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.
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.
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).
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.
Select your entire data range, go to the 'Data' tab on the ribbon, and click 'Filter'.
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 VBA Macro to Automatically Hide Rows
For desktop versions of Excel (Windows or Mac), you can write a short VBA script to automatically evaluate the four cells and hide the entire row without using manual filters.
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. Open your file in WPS: Launch WPS Spreadsheet and open your existing Excel workbook.
- 2. Apply the helper formula: Create a new column and input the =COUNTA() formula to flag rows with empty cells.
- 3. Filter the rows: Navigate to the Data tab, click Filter, and deselect the rows marked as blank.
- 4. Utilize VBA: Alternatively, go to the Developer tab to open the VBA editor and execute your row-hiding macro directly.

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.




