Boucle VBA

Résolu
happy4u Messages postés 39 Date d'inscription   Statut Membre Dernière intervention   -  
happy4u Messages postés 39 Date d'inscription   Statut Membre Dernière intervention   -
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 8561 Date d'inscription   Statut Membre Dernière intervention   1 780
 
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   Statut Membre Dernière intervention  
 
Thank you :))
0