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
| Private Sub get_voiture()
Dim n_sell As Long
Dim n_marq As Long
Dim i As Long
Dim wsData As Worksheet
Dim wsDetail As Worksheet
Dim r As Long
Dim lastRow As Long
' Définir les feuilles de calcul
Set wsData = ThisWorkbook.Sheets("Data")
Set wsDetail = ThisWorkbook.Sheets("Détail")
n_sell = ucols("CA")
n_marq = ucols("Produit")
voiture = 0
For i = LBound(tdata, 1) + 1 To UBound(tdata, 1)
If (voiture_dic.Exists(tdata(i, n_prod))) Then
On Error Resume Next
voiture = voiture + tdata(i, n_sell)
End If
Next i
If (tglobalCA <> 0) Then
voiture = voiture / tglobalCA
End If
' Trouver la dernière ligne dans la feuille de calcul "Data"
lastRow = wsData.Cells(wsData.Rows.Count, "A").End(xlUp).Row
' Parcourir chaque ligne dans la feuille de calcul "Data"
For r = 1 To lastRow
' Vérifier si la marque de voiture est dans le dictionnaire
If voiture_dic.Exists(wsData.Cells(r, n_marq).Value) Then
' Copier la ligne dans la feuille de calcul "Détail"
wsData.Rows(r).Copy wsDetail.Cells(wsDetail.Rows.Count, "A").End(xlUp).Offset(1, 0)
End If
Next r
End Sub |
Partager