VBA For Loop – Loop Through a Range of Cells

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 demostrate how to loop through a range. You can replace the range value for whatever range you need to loop through.

Loop Through Entire Column

The first example loops through the entire column A range. 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 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 Easy VBA. A VBA add-in to quickly insert any of the sample code found on our site directly into the Visual Basic Editor, save your own frequently used code, and more!

alt text

Stop searching for VBA code online. Try the Code VBA Add-in…

Learn More!

<<Return to VBA Examples

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

Leave A Comment