Boucle For Each...Next

La boucle For Each...Next permet d’accéder aux objets d’une collection.

Exemple :

Sub ColorieCellule()

Dim MaPlage As Range

Dim Cellule As Range

Dim i As Integer

Set MaPlage = Range("A1:B5")

For Each Cellule In MaPlage

Cellule.Interior.ColorIndex = i

i = i + 1

Next Cellule

End Sub

Modifié le: lundi 14 novembre 2016, 18:42