How to Fix Excel VBA Not Hiding Rows Based on Cell Value
Question details
An Excel VBA macro successfully hides one group of rows but ignores another because the conditional text comparison is inconsistently handling capital and lowercase letters.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Writing an Excel VBA script to automatically hide specific rows when a certain text value, such as "No", is entered into a target cell.
- Observed behavior
- The macro fails to execute the row-hiding command for some cells because it treats variations like "No" and "NO" as completely different values due to default case sensitivity.
Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) and identify the exact cell references and row numbers you intend to hide before modifying your code.
Use LCase for Case-Insensitive Comparison
Modify your VBA code to convert the cell value to lowercase before comparing it to your target text, ensuring all capitalization variations are caught.
By default, VBA string comparisons are binary, meaning they are strictly case-sensitive. Using the LCase function normalizes the input so your conditional statements work reliably regardless of how the user typed the value.
Press Alt + F11 to open the VBA Editor, find the module containing your row-hiding script, and locate the line where you compare the cell value to your target string.
Modify the cell reference using the LCase function and ensure the text string you are comparing it against is strictly lowercase. Update your code to look like this: LCase(Range("I90").Value) = "no".

Implement a Worksheet_Change Event
Use a Worksheet_Change event to trigger the row-hiding macro automatically and dynamically whenever the target cell is updated.
Write and Run VBA Macros Seamlessly in WPS Spreadsheets
WPS Office provides excellent support for VBA macros. You can edit, execute, and debug your VBA code, including complex Worksheet_Change events and text functions, directly within the WPS Spreadsheets environment.
- 1. Open your spreadsheet in WPS Office: Launch WPS Spreadsheets and open your Macro-Enabled Workbook containing the row-hiding scripts.
- 2. Access the Developer tools: Navigate to the 'Developer' tab on the top ribbon. If it is not visible, you can enable it in the settings.
- 3. Launch the VBA Editor: Click on 'Visual Basic' or 'Macros' to open the built-in VBA editor where you can adjust your code using LCase and Intersect methods exactly as you would in Microsoft Excel.

Frequently Asked Questions
Why does VBA consider "No" and "NO" as different values?
By default, VBA uses binary string comparison, meaning it strictly evaluates the exact ASCII characters. Capital 'N' and lowercase 'n' have different ASCII values, so they are treated as entirely different inputs unless you force a case-insensitive comparison.
How do I hide multiple non-adjacent rows using VBA?
You can specify multiple distinct ranges separated by commas inside a single Range object. For example, using Range("10:15, 20:25").EntireRow.Hidden = True will simultaneously hide rows 10 through 15 and rows 20 through 25.
What is the Worksheet_Change event in VBA?
Worksheet_Change is a built-in event trigger in Excel VBA that automatically runs a specified macro whenever a user modifies the value of any cell within that designated worksheet.




