VBA For Loop – Loop Through a Range of Cells

Associated Files Download Links

In VBA, you can loop through a range of cells, applying actions to each cell in the range.

 

If you want to test a condition for each cell in a range using VBA, the best way is to loop through the range, testing each cell. Here are two code examples to demonstrate how to loop through a range. You can replace the range value for whatever range you need to loop through.

Loop Through Range of Cells

This example will loop through a range of cells. The if statement tests the condition if the cell contains the text “FindMe” and shows a message box with the location of the text if found.

Loop Through Entire Column

This example loops through the entire column A range.

Loop Through Entire Row

The next example loops through row 1 considering the entire row a range.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

alt text

 

Learn More!


<<Return to VBA Examples

Did you find this VBA tutorial useful? Then share it with your friends and colleagues:

You may also like some of this related content...

MS has a new KB article with some basic code examples for filling an array
UsedRange - Find Last Used Cell, Column or Row The following code will return in
The standard Excel “Column” Function returns the number rather than the letter of the column
Named Ranges Using named ranges when programming references to cells can save you time and
Find Max Value For Each Column in Range The following function will return the Maximum
Advertisements
Automate Excel
Left Menu Icon