Excel - Power Query - Power Pivot - VBA

Boucles

For ... Next

Visual Basic propose différentes boucle, nous montrons ici la plus utilise dans Excel :

For compteur = debut To Fin Step Pas
  instructions
  Exit For
Next

Exemple :

For i = 1 to 10
  Debug.Print i
Next

For Each ... Next

For Each objet In collection d'objets
  instructions
  Exit For
Next

Par exemple, les instructions suivantes renomment chaque feuille du classeur actif, en les nommant “Feuille 1”, “Feuille 2”, etc.

Dim ws As WorkSheet
Dim a
For Each ws In ActiveWorkbook.Worksheets
  ws.name = "Feuille " & a
  a = a + 1
  Exit For
Next