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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| Private Sub RecupPeriode(wsExtractVolume As Worksheet)
Dim i, j As Integer 'Compteur i pour les 3 premiers lignes du fichier extract volume, j pour les colonnes
Dim iColMois As Integer 'colonne contenant par exemple nov'20
Dim iColTotal As Integer 'colonne contenant total
Dim jColMois As Integer 'compteur pour la colonne mois
Dim jColTotal As Integer 'compteur pour la colonne total
Dim bTotalTrouve As Boolean 'Colonne total trouvé
Dim bMoisTrouve As Boolean 'Colonne mois trouvé
Dim bColTotalAnneNMoin1 As Boolean 'colonne total annee n moins 1 trouvé
Dim bColTotalAnneN As Boolean 'colonne total annee n trouvé
Dim bAnneeTrouve As Boolean 'indique si l'année a été trouvé
If Not MODE_DEBUG Then On Error GoTo ErrLabel
iColMois = 0
iColTotal = 0
bTotalTrouve = False
bMoisTrouve = False
bAnneeTrouve = False
bColMoisAnneNMoin1 = False
bColMoisAnneN = False
bColTotalAnneNMoin1 = False
bColTotalAnneN = False
Call gLog.WriteTitle2("Récupération des colonnes total et mois dans le fichier Extract volume")
'Filtrer sur les données du tableau d'extract en fonction de l'enseigne
For i = 1 To 2
'Parcourt des colonnes pour trouver la colonne total et la colonne du mois selectionné
For j = 1 To wsExtractVolume.Cells(i, Columns.Count).End(xlToLeft).Column
If wsExtractVolume.Cells(i, j) = "Total" Then
If bTotalTrouve = False Then
iColTotal = j
bTotalTrouve = True
End If
Else
'Est ce que l'on trouve le mois selectionné et l'année
Debug.Print Left(wsExtractVolume.Cells(i, j), 3)
Debug.Print "20" & Right(wsExtractVolume.Cells(i, j), 2)
Debug.Print Left(ThisWorkbook.Worksheets("PARAMS").Range("LBL_MOIS").Value, 3)
Debug.Print ThisWorkbook.Worksheets("PARAMS").Range("LBL_SEL_ANNEE").Value
If Left(wsExtractVolume.Cells(i, j), 3) = Left(ThisWorkbook.Worksheets("PARAMS").Range("LBL_MOIS").Value, 3) _
And Right(wsExtractVolume.Cells(i, j), 2) = Right(ThisWorkbook.Worksheets("PARAMS").Range("LBL_SEL_ANNEE").Value, 2) Then
If bMoisTrouve = False And bAnneeTrouve = False Then
iColMois = j
bMoisTrouve = True
bAnneeTrouve = True
End If
End If
End If
Next j
'Si mois trouvé on cherche les colonnes Cols et Cols ant. après la ligne 1
If iColMois <> 0 Then
If i > 1 Then
For jColMois = iColMois To iColMois + 3
If wsExtractVolume.Cells(i, jColMois).Value = "Cols" And bColMoisAnneN = False Then
giColMoisAnneN = jColMois
bColMoisAnneN = True
End If
If wsExtractVolume.Cells(i, jColMois).Value = "Cols ant." And bColMoisAnneNMoin1 = False Then
giColMoisAnneNMoin1 = jColMois
bColMoisAnneNMoin1 = True
End If
Next jColMois
End If
End If
'Si total trouvé on cherche les colonnes Cols et Cols ant. après la ligne 1
If iColTotal <> 0 Then
If i > 1 Then
For jColTotal = iColTotal To iColTotal + 3
If wsExtractVolume.Cells(i, jColTotal).Value = "Cols" And bColTotalAnneN = False Then
giColTotalAnneN = jColTotal
bColTotalAnneN = True
End If
If wsExtractVolume.Cells(i, jColTotal).Value = "Cols ant." And bColTotalAnneNMoin1 = False Then
giColTotalAnneNMoin1 = jColTotal
bColTotalAnneNMoin1 = True
End If
Next jColTotal
End If
End If
Next i
' If bTotalTrouve = False Or bMoisTrouve = False Then
' Err.Description = "Ceci est un test"
' Err.Number = 522
' Call Err.Raise(Err.Number)
' End If
If bTotalTrouve = False Or bMoisTrouve = False Then GoTo ErrLabel
' If bMoisTrouve = False Then
' Err.Description = "Colonne du mois et de l'année selectionné introuvable dans le fichier Extract Volume"
' Err.Number = 522
' Call Err.Raise(Err.Number)
' End If
Exit Sub
ErrLabel:
Call gLog.WriteError("Erreur rencontrée dans la procédure RecupPeriode du module " & MODULE_NAME, True)
If bTotalTrouve = False Then
Call gLog.WriteIndentedLine("Colonne total introuvable dans le fichier Extract Volume", 1, True)
End If
If bMoisTrouve = False Then
Call gLog.WriteIndentedLine("Colonne du mois et de l'année selectionné introuvable dans le fichier Extract Volume", 1, True)
End If
Call Err.Raise(Err.Number)
End Sub |
Partager