For Each Next Loop

For Each Next Loop in VBA The true way to perform automatic calculations is to use the looping process. Another easy way to loop through a range in Microsoft Excel is to use a For Each…Next loop with the collection of cells specified in the Range property. The macro automatically sets an object variable for the next cell each time the loop runs. The following Microsoft Excel training video describes a procedure that loops through the range B2:B10, setting to ‘pink’ all values greater than or equal to 9000.Another instance of conditional formatting! Macro code:

Sub ColorMyCells()

For Each c in Worksheets(“Sheet1”).Range(“B2:B10”).Cells If c.Value>=9000 Then



End Sub

Watch the training video:

Further reading: For Each…Next Statement (Visual Basic)

Leave a Reply

Your email address will not be published. Required fields are marked *