VBA & Macro Problems

How to Fix Excel VBA Not Hiding Rows Based on Cell Value

Aamir Naveed AkramAamir Naveed Akram Nov 3, 2026 870 views

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.

How to Fix Excel VBA Not Hiding Rows Based on Cell Value
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.
Before you start

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.

Solution 1Recommended

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.

1
Locate your conditional statement

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.

2
Wrap the range value with LCase

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".

Use LCase for Case-Insensitive Comparison
Option Compare Text: Alternatively, you can add 'Option Compare Text' at the very top of your VBA module to make all string comparisons in that module case-insensitive by default.
Advanced Macro Support

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. 1. Open your spreadsheet in WPS Office: Launch WPS Spreadsheets and open your Macro-Enabled Workbook containing the row-hiding scripts.
  2. 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. 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.
Fully compatible with Microsoft Excel .xlsm and .xlsb formatsBuilt-in VBA editor for seamless macro management and debuggingFamiliar user interface requiring no steep learning curveLightweight performance that easily handles complex datasets
microsoft office alternative - wps office

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.