VBA For Loop – Loop Through a Range of Cells

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

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)