[VB] Aide boucle Do While...

Résolu
alphonse -  
 alphonse -
Bonjour,

J'ai un tableau.
1 a
2 b
3 c

Je voudrais placer automatiquement les 1 , 2 ,3 jusqu'a ce qu'il n'y ai plus de lettres dans l'autre colonne. Au passage je voudrais que le 1,2,3, commence selon K1 (initid). Si k1 = 11 alors on fait 11,12,13... (K1 étant la dernière valeur du précédent calcul). Mais là je m'embrouille vraiment dans mon script, et j'arrive à rien... Pouvez vous m'aider ?

compteur2 = 1
Do While Sheets("appartenir").Cells(compteur2, 2) <> 0
compteur2 = compteur2 + 1
initid = Sheets("calc").Cells(1, 11).Value
Sheets("appartenir").Cells(compteur2, 1) = initid + 1
Sheets("calc").Cells(1, 11) = initid
Loop

2 réponses

  1. michel_m Messages postés 18903 Date d'inscription   Statut Contributeur Dernière intervention   3 320
     
    Bonjour

    En supposant que cells(1;11) est fixe (on aurait pu écrire range("K1")

    Option Explicit
    
    Sub xxxx()
    Dim init_id As Long, derlig As Long, compteur2 As Long
    
    init_id = Sheets("calc").Cells(1, 11)
    Application.ScreenUpdating = False
    
    With Sheets("appartenir")
        derlig = .Cells(.Cells.Rows.Count, 2).End(xlUp).Row
        For compteur2 = 1 To derlig
            .Cells(compteur2, 1) = init_id
            init_id = init_id + 1
        Next
    End With
    Sheets("calc").Cells(1, 11) = init_id
    End Sub

    1
  2. alphonse
     
    Merci Michel. Ce n'est pas la première fois que tu me sauves. ;). Avant (il y a longtemps) c'était en Php il me semble.

    Il fallait connaitre : "derlig = .Cells(.Cells.Rows.Count, 2).End(xlUp).Row"

    ça fonctionne parfaitement bien.

    Bonne journée a toi.
    0