Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

XL 2016 Boucle espacé de 3 colonnes

poussy67

XLDnaute Occasionnel
Bonjour Le forum

Je cherche un moyen de simplifier un code Boucle sans succès. Faire une simple boucle pas de souci,
mais de faire une boucle qui me remplit la cellule espacer de 3 colonnes que je n'arrive pas à résoudre.
Je fais appel au pro d'excel pour un petit coup de pouce.

Les colonnes concernés sont D-G-J-M-P-S-V-Y-AB-AE-AH-AK

With Sheets("Cash")
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, 4).Value = ComboBox1
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, 7).Value = ComboBox2
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, 10).Value = ComboBox3
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, 13).Value = ComboBox4
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, 16).Value = ComboBox5
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, 19).Value = ComboBox6
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, 22).Value = ComboBox7
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, 25).Value = ComboBox8
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, 28).Value = ComboBox9
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, 31).Value = ComboBox10
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, 34).Value = ComboBox11
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, 37).Value = ComboBox12
End With

J'ai essayer ce ci sans succès

For i = 1 To 12
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, i + 3) = Me.Controls("ComboBox" & i)
Next i

En vous remerciant d'avance.

Cdt
 

Hasco

XLDnaute Barbatruc
Repose en paix
Bonjour,

VB:
lig = Me.ComboBoxNom.ListIndex + 2
    With Sheets("Cash")
        For i = 1 To 12
            col = 4 + ((i - 1) * 3)
            .Cells(lig, col).Value = Me.Controls("ComboBox" & i).Value
        Next i
    End With

cordialement
 

poussy67

XLDnaute Occasionnel
Bonjour Sylvanu

j'ai testé cela fonctionne très bien.
Je te remercie pour ton aide

For i = 1 To 12
Sheets("Cash").Cells(ComboBoxNom.ListIndex + 2, 3 * i + 1) = Me.Controls("ComboBox" & i)
Next i
Cdt
 

Discussions similaires

Réponses
3
Affichages
591
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…