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
| Sub Cherche()
Dim L As Integer 'variable pour la boucle
Dim nb_lignes As Long 'variable pour le nombre de ligne
Dim adsl As Single 'variable résultat 1er if
Dim Alimentation As Single 'variable second if
Dim Assurance As Single
Dim CAF As Single
'initialisation des variables
L = 1
adsl = 0
Alimentation = 0
Assurance = 0
CAF = 0
'comptage et stockage du nombre de ligne pour l'onglet 9
Sheets(9).Select
nb_lignes = WorksheetFunction.CountA(Range("A:A")) + 1
'Boucle des controles + additions des valeurs numériques (débit, crédit)
For L = 1 To nb_lignes
If Range("B" & L) = Sheets("Bilan").Range("A11").Value Then
adsl = adsl + Range("D" & L).Value + Range("E" & L).Value
ElseIf Range("B" & L) = Sheets("Bilan").Range("A12").Value Then
Alimentation = Alimentation + Range("D" & L).Value + Range("E" & L).Value
ElseIf Range("B" & L) = Sheets("Bilan").Range("A13").Value Then
Assurance = Assurance + Range("D" & L).Value + Range("E" & L).Value
ElseIf Range("B" & L) = Sheets("Bilan").Range("A13").Value Then
Assurance = Assurance + Range("D" & L).Value + Range("E" & L).Value
ElseIf Range("B" & L) = Sheets("Bilan").Range("A14").Value Then
CAF = CAF + Range("D" & L).Value + Range("E" & L).Value
End If
Next L
'report des résultats
Sheets("Bilan").Select
Range("J11").Value = adsl
Range("J12").Value = Alimentation
Range("J13").Value = Assurance
Range("J14").Value = CAF
End Sub |
Partager