Boucle VBA

Résolu/Fermé
happy4u Messages postés 39 Date d'inscription vendredi 28 octobre 2016 Statut Membre Dernière intervention 17 septembre 2017 - Modifié par happy4u le 20/01/2017 à 15:39
happy4u Messages postés 39 Date d'inscription vendredi 28 octobre 2016 Statut Membre Dernière intervention 17 septembre 2017 - 20 janv. 2017 à 15:39
Bonjour,


comment peut on mettre ce bout de code en boucle?
Workbooks("s1.xlsm").Sheets("feuil1").Cells(Rows.Count, 5).End(xlUp)(2) = x.Offset(2).Value * 10 ^ 6
             Workbooks("s1.xlsm").Sheets("feuil1").Cells(Rows.Count, 6).End(xlUp)(2) = x.Offset(3).Value * 10 ^ 6
                  Workbooks("s1.xlsm").Sheets("feuil1").Cells(Rows.Count, 8).End(xlUp)(2) = x.Offset(4).Value * 10 ^ 6
                     Workbooks("s1.xlsm").Sheets("feuil1").Cells(Rows.Count, 9).End(xlUp)(2) = x.Offset(5).Value * 10 ^ 6
                     Workbooks("s1.xlsm").Sheets("feuil1").Cells(Rows.Count, 10).End(xlUp)(2) = x.Offset(6).Value * 10 ^ 6
                  Workbooks("s1.xlsm").Sheets("feuil1").Cells(Rows.Count, 11).End(xlUp)(2) = x.Offset(7).Value * 10 ^ 6
             Workbooks("s1.xlsm").Sheets("feuil1").Cells(Rows.Count, 12).End(xlUp)(2) = x.Offset(8).Value * 10 ^ 6
           Workbooks("s1.xlsm").Sheets("feuil1").Cells(Rows.Count, 7).End(xlUp)(2) = x.Offset(9).Value * 10 ^ 6


merci !!

1 réponse

Patrice33740 Messages postés 8556 Date d'inscription dimanche 13 juin 2010 Statut Membre Dernière intervention 2 mars 2023 1 775
20 janv. 2017 à 15:30
Bonjour

On peut toujours mais c'est pas forcément utile :
With Workbooks("s1.xlsm").Sheets("feuil1")
 j = 2
 For i = 5 To 12
  If i = 7 Then
   .Cells(Rows.Count, i).End(xlUp)(2) = x.Offset(j + 2).Value * 10 ^ 6
  Else
   .Cells(Rows.Count, i).End(xlUp)(2) = x.Offset(j).Value * 10 ^ 6
   j = j + 1
  End If
 Next i
End With
0
happy4u Messages postés 39 Date d'inscription vendredi 28 octobre 2016 Statut Membre Dernière intervention 17 septembre 2017
20 janv. 2017 à 15:39
Thank you :))
0