Correct Excel VBA Syntax for Multiple Noncontiguous Ranges
Question details
The user is attempting to use VBA to create visual checkboxes across multiple noncontiguous ranges but experiences inconsistent behavior where incorrect cells are modified.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Using VBA and Wingdings 2 characters to create lightweight visual indicators (checkboxes) instead of slow built-in form controls across noncontiguous columns.
- Observed behavior
- When applying VBA code to multiple ranges combined in a single statement, the second range misbehaves, allowing both Yes and No boxes to be checked and placing characters in unintended cells.
Ensure you have the Developer tab enabled in your spreadsheet and save a backup copy of your workbook before testing new VBA macro code.
Use Correctly Quoted Range Strings and Application.Intersect
Fix syntax errors by properly quoting the noncontiguous ranges and using Application.Intersect to isolate the target cell's behavior.
When handling a Worksheet_SelectionChange event, referencing multiple ranges as one combined object can cause relative cell offsets to behave unpredictably. Using Application.Intersect ensures the macro only triggers if the exact active cell falls within your defined boundaries.
Press Alt + F11 to open the Visual Basic for Applications editor, and double-click the specific worksheet in the Project Explorer where you want the checkboxes.
Format your range string correctly with a comma separating the areas inside a single pair of quotes, for example: Me.Range("D407:E424,I407:J424").
Wrap your target validation using If Not Application.Intersect(Target, Me.Range("D407:E424,I407:J424")) Is Nothing Then. This guarantees the code only proceeds when the user clicks inside these specific areas.
Instead of applying relative offsets to a combined range, check the specific Target.Column to clear the opposite checkbox. For example, if Target.Column = 4 (Column D), clear Column E. If Target.Column = 9 (Column I), clear Column J.

Process Ranges Independently via Helper Subroutines
Separate the logic for different noncontiguous blocks into distinct conditions to prevent variable overlap and misplaced characters.
Manage Macros and VBA Seamlessly in WPS Office
WPS Spreadsheet provides excellent support for VBA and macros, allowing you to create custom visual checkboxes, debug code efficiently, and optimize large workbooks without performance drops.
- 1. Download and Install WPS Office: Get the latest version of WPS Office and open your macro-enabled spreadsheet (.xlsm).
- 2. Access the Developer Tools: Navigate to the Developer tab on the top ribbon and click on 'Visual Basic' to open the VBA Editor.
- 3. Edit the Range Syntax: Paste or modify your noncontiguous range macro code inside the worksheet object.
- 4. Save and Run: Save your progress and test the visual checkbox behavior natively within the WPS Spreadsheet interface.

Frequently Asked Questions
Why do built-in form checkboxes slow down my Excel workbook?
Adding hundreds of individual shape objects (like form controls) drastically increases the file size and rendering load. Using VBA and Wingdings 2 font characters as visual indicators is a much lighter alternative that preserves performance.
How do I check if a cell is within multiple noncontiguous ranges in VBA?
You can use the Application.Intersect method. For example: `If Not Application.Intersect(Target, Range("A1:A10, C1:C10")) Is Nothing Then`. If it does not evaluate to Nothing, the active cell is inside the specified noncontiguous ranges.
Why does Me.Range behave unexpectedly when looping through multiple areas?
When you combine noncontiguous ranges, iterating blindly through `.Cells` or applying relative `.Offset` commands can cross into unmapped boundaries. It is safer to loop through `Range.Areas` or handle the intersect logic for the specific Target cell directly.




