[VB] Aide boucle Do While...

Résolu/Fermé
alphonse - 24 janv. 2011 à 09:06
 alphonse - 24 janv. 2011 à 14:55
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
A voir également:

2 réponses

michel_m Messages postés 16603 Date d'inscription lundi 12 septembre 2005 Statut Contributeur Dernière intervention 16 décembre 2023 3 303
24 janv. 2011 à 10:22
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
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