1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
Sub test_copy()
Dim vlrn As Long
Dim vlrn1 As Long
Dim amount As String
Dim chaque_formule As String
Dim chaque As Integer
Dim chaque1 As Integer
Dim Cpt_Lignes As Integer
With Worksheets("Macrodata")
'Boucle
vlrn = 2
Do While .Range("C" & vlrn).Value <> ""
'formule pour la colonne chaque
chaque_formule = "=IF(AND(I" & vlrn & ">=K" & vlrn & ",I" & vlrn & "<>""""),IF(I" & vlrn & "/K" & vlrn & "<1.5,2,int(I" & vlrn & "/K" & vlrn & ")),0)"
.Range("L" & vlrn).Formula = chaque_formule
chaque = Cells(vlrn, 12).Value
'condition sur la colonne J="WRONG"
If Cells(vlrn, 10).Value = "WRONG" Then
chaque1 = chaque + vlrn
vlrn1 = vlrn + 1
'copie la partie fixe
.Range("C" & vlrn & ":G" & vlrn).Copy .Range("C" & vlrn1 & ":G" & chaque1)
.Range("K" & vlrn & ":K" & vlrn).Copy .Range("K" & vlrn1 & ":K" & chaque1)
'complète le montant et "TRUE"
amount = "=I$" & vlrn & "/L$" & vlrn & ""
.Range("H" & vlrn1 & ":H" & chaque1) = amount
.Range("J" & vlrn1 & ":J" & chaque1) = "TRUE"
End If
'pour sauter les lignes copiées
vlrn = vlrn + chaque + 1
Loop
'==============copier sur la feuille SYNTHESE=====================
'compteur du nombre de lignes sur la feuille "Macrodata"
Cpt_Lignes = 1
Do While .Range("C" & Cpt_Lignes).Value <> ""
Cpt_Lignes = Cpt_Lignes + 1
Loop
Cpt_Lignes = Cpt_Lignes - 1
'copie des données sur la feuille SYNTHESE
.Range("A1:J" & Cpt_Lignes).Copy
Worksheets("Synthèse").Range("A1").PasteSpecial xlPasteValues
'supprime les lignes = "WRONG"
vlrn = 2
Do While Worksheets("Synthèse").Range("C" & vlrn).Value <> ""
If Worksheets("Synthèse").Cells(vlrn, 10).Value = "WRONG" Then
Worksheets("Synthèse").Cells(vlrn, 10).EntireRow.Delete
End If
vlrn = vlrn + 1
Loop
End With
End Sub |
Partager