VBA & Macro Problems

How to Loop Through Non-Adjacent Columns in Excel VBA

Elise WilliamsElise Williams Nov 3, 2026 869 views

Question details

The user needs to process specific rows in two separate, non-consecutive columns using Excel VBA without affecting the columns in between.

How to Loop Through Non-Adjacent Columns in Excel VBA
Product
Excel VBA
Device & OS
not provided
Scenario
Writing a VBA macro to iterate through specific cells in separate columns, such as Column A and Column L, for rows 89 through 103.
Observed behavior
Using standard range syntax incorrectly selects the entire rectangular block spanning all columns between the two references. The goal is to isolate the loop strictly to the specified non-adjacent columns.
Before you start

Ensure you have the Developer tab enabled in Excel and have a basic understanding of writing VBA macros in the Visual Basic Editor.

Solution 1Recommended

Use a Comma-Separated Multiple-Area Range Syntax

Define the range using a comma within the address string to explicitly create two separate areas for the loop.

When you use a comma-separated string like Range("A89:A103, L89:L103"), Excel creates a multiple-area range. This prevents the macro from processing the columns in between.

Alternatively, using two separate string arguments like Range("A89:A103", "L89:L103") instructs Excel to draw a box from the top-left coordinate to the bottom-right coordinate, unintentionally including columns B through K.

1
Open Visual Basic Editor

Press ALT + F11 to open the VBA Editor in Excel, then insert or open your target module.

2
Define the Range Variable

Declare your range variable and set it using the single-string, comma-separated syntax. For example: Set rngOccasion = Range("A89:A103, L89:L103").

3
Create the For Each Loop

Write a For Each loop to iterate through the cells: For Each cl In rngOccasion.Cells.

4
Process and Close the Loop

Insert your desired code to process each cell (referenced as cl), then close the loop by typing Next cl.

Use a Comma-Separated Multiple-Area Range Syntax
Syntax Warning: Do not separate the range arguments with quotes and a comma like Range("A89:A103", "L89:L103"). This creates a continuous rectangular range spanning all columns from A to L.
Seamless VBA Integration

Write and Execute VBA Macros Effortlessly in WPS Office

WPS Spreadsheet provides excellent compatibility with Excel VBA, allowing you to run your multiple-area range loops seamlessly. You can edit, debug, and execute macros with familiar syntax.

  1. 1. Open WPS Spreadsheet: Launch WPS Office and open your macro-enabled workbook.
  2. 2. Access the Developer Tools: Go to the Developer tab on the ribbon and click on 'VBA Editor' to launch the coding environment.
  3. 3. Run Your Code: Insert your non-adjacent range loop code and press F5 to execute it directly within WPS Spreadsheet.
Fully supports Excel VBA macros and multiple-area range scripts.High compatibility with Microsoft Excel (.xls, .xlsx, .xlsm) macro formats.Lightweight installation with a user-friendly interface.
microsoft office alternative - wps office

Frequently Asked Questions

How do I loop through each area of a multiple-area range separately?

You can nest your loops. First, loop through the areas using 'For Each rngArea In rngOccasion.Areas', and then loop through the cells within that specific area using 'For Each cl In rngArea.Cells'.

Why is my VBA loop processing the columns I wanted to skip?

This happens if you use the syntax Range("A89:A103", "L89:L103"). Excel interprets this as the top-left and bottom-right corners of a single rectangle, effectively selecting all columns from A to L. Always use a single string with a comma Range("A89:A103, L89:L103") to keep them separate.

Can I select more than two non-adjacent columns using this method?

Yes, you can add as many ranges as you need within the same string, separated by commas. For example: Range("A1:A10, C1:C10, E1:E10") will successfully loop through all three non-adjacent areas.