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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
| Sub SuiviCashBnpEuro()
' Déclaration des Variables
Dim i As Integer
Dim S As Variant
Dim neg1 As Long
Dim neg2 As Long
Dim neg3 As Long
Dim pos1 As Long
Dim pos2 As Long
Dim pos3 As Long
Dim Wbk1 As Workbook
Dim Wbk2 As Workbook
Dim c As Range
Dim Num_Lig As Long
Set Wbk1 = ThisWorkbook
' Choix du fichier
Rep = MsgBox("Veuillez choisir le fichier", vbOKCancel, "Chargement du Fichier")
If Rep = vbCancel Then Exit Sub
ChDrive ("C")
ChDir "C:\EMPLACEMENT OU IL Y A LE DOCUMENT A CHOISIR"
fichier = Application.GetOpenFilename("Excel files(*.xls), C:\EMPLACEMENT OU IL Y A LE DOCUMENT*.xls")
' Sorti de procédure + Message d'erreurs si fichier non choisi
On Error GoTo MsgErreurs
Workbooks.Open Filename:=fichier
MsgBox "Le fichier " & x & " est ouvert"
Set Wbk2 = Workbooks.Open(Filename:=fichier)
Cells.Select
Cells.EntireColumn.AutoFit
' Renseignement sur le classeur actif
classeur = ActiveWorkbook.Name
feuille = ActiveSheet.Name
DateValeur = Range("B4").Value
' Activation de l'autre fichier
Wbk1.Activate
' Recherche de la ligne à incrémenter en fonction de la date de valeur
With Sheets("Feuil1")
Set c = .Range("A:A").Find(DateValeur, LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
Num_Lig = c.Row
Set c = Nothing
End If
If Num_Lig > 0 Then
MsgBox Num_Lig
Else
MsgBox "Date inéxistante"
End If
End With
' Activation du fichier choisi
Wbk2.Activate
'Compteur du nombre de ligne à balayer (ie: cellules pleines)
S = Application.WorksheetFunction.CountA(Range("A:A"))
'Balayage de la plage de données et Classement selon catégories
For i = 6 To S Step 1
If InStr(1, Cells(i, 3).Value, "FRAMBOISE", vbTextCompare) Or InStr(1, Cells(i, 3).Value, "MURE", vbTextCompare) Or InStr(1, Cells(i, 3).Value, "FRAISE", vbTextCompare) <> 0 Then
Cells(i, 6).Value = "FRUIT"
Else
If InStr(1, Cells(i, 3).Value, "CROISSANT", vbTextCompare) Or InStr(1, Cells(i, 3).Value, "VIENNOISE", vbTextCompare) Or InStr(1, Cells(i, 3).Value, "CHOUCREME", vbTextCompare) <> 0 Then
Cells(i, 6).Value = "VIENNOISERIE"
Else
If InStr(1, Cells(i, 3).Value, "PORC", vbTextCompare) Or InStr(1, Cells(i, 3).Value, "BOEUF", vbTextCompare) Or InStr(1, Cells(i, 3).Value, "DINDE", vbTextCompare) Or InStr(1, Cells(i, 3).Value, "VOLAILLE", vbTextCompare) Or InStr(1, Cells(i, 3).Value, "POULET", vbTextCompare) Or InStr(1, Cells(i, 3).Value, "AGNEAU", vbTextCompare) <> 0 Then
Cells(i, 6).Value = "VIANDE"
' ETCETERA CAR IL Y A BCP DE CATEGORIES
Else
Cells(i, 6).Value = "A CLASSER"
End If
End If
End If
End If
Next i
'Tri par ordre alphabétique
Range("A6:F" & S).Select
Selection.Sort Key1:=Range("F6"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'Création de listes déroulantes concernant les A CLASSER
For i = 6 To S Step 1
If Range("F" & i) = "A CLASSER" Then
Range("F" & i).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="FRUIT,VIENNOISERIE,VIANDE"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End If
Next i
'C'EST ICI QUE JE VOUDRAIS METTRE UN CLIVAGE POUR QUE L'UTILISATEUR SELECTIONNE DANS LES LISTES DEROULANTES DES CATEGORIES A CLASSER LA BONNE CATEGORIE
'Tri par ordre alphabétique
Range("A6:F" & S).Select
Selection.Sort Key1:=Range("F6"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'Somme par catégories
For i = 6 To S Step 1
On Error Resume Next
If Cells(i, 6).Value = "FRUIT" Then
neg1 = neg1 + Val((Cells(i, 4)))
pos1 = pos1 + Val((Cells(i, 5)))
Else
If Cells(i, 6).Value = "VIENNOISERIE" Then
neg2 = neg2 + Val((Cells(i, 4)))
pos2 = pos2 + Val((Cells(i, 5)))
Else
If Cells(i, 6).Value = "VIANDE" Then
neg3 = neg3 + Val((Cells(i, 4)))
pos3 = pos3 + Val((Cells(i, 5)))
'ETCETERA
End If
End If
End If
Next i
' Création d'une nouvelle feuille nommée Somme
Sheets.Add.Move after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "Somme"
ActiveCell.FormulaR1C1 = "CATEGORIES"
Range("A2").Select
ActiveCell.FormulaR1C1 = "FRUIT"
Range("A3").Select
ActiveCell.FormulaR1C1 = "VIENNOISERIE"
Range("A4").Select
ActiveCell.FormulaR1C1 = "VIANDE"
Range("A5").Select
Range("B1").Select
ActiveCell.FormulaR1C1 = "NEGATIF"
Range("C1").Select
ActiveCell.FormulaR1C1 = "POSITIF"
Range("B2,B9").Select
With Selection.Interior
.ColorIndex = 27
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Range("C5:C8").Select
With Selection.Interior
.ColorIndex = 46
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
' Tableau des montants par catégories
Cells(2, 2) = neg1
Cells(3, 2) = neg2
Cells(4, 2) = neg3
Cells(2, 3) = pos1
Cells(3, 3) = pos2
Cells(4, 3) = pos3
'ETCETERA
Cells.Select
Cells.EntireColumn.AutoFit
ActiveWorbook.Save
'COPIE SUR L'AUTRE CLASSEUR
Set Wbk1 = ThisWorkbook
If Range("C2") <> 0 Then
Wbk2.Sheets("Somme").Range("C2").Copy _
Destination:=Wbk1.ActiveSheet.Range("J" & Num_Lig)
End If
If Range("B3") <> 0 Then
Wbk2.Sheets("Somme").Range("B3").Copy _
Destination:=Wbk1.ActiveSheet.Range("" & Num_Lig)
End If
If Range("C3") <> 0 Then
Wbk2.Sheets("Somme").Range("C3").Copy _
Destination:=Wbk1.ActiveSheet.Range("K" & Num_Lig)
End If
If Range("B4") <> 0 Then
Wbk2.Sheets("Somme").Range("B4").Copy _
Destination:=Wbk1.ActiveSheet.Range("I" & Num_Lig)
End If
If Range("C4") <> 0 Then
Wbk2.Sheets("Somme").Range("C4").Copy _
Destination:=Wbk1.ActiveSheet.Range("M" & Num_Lig)
End If
If Range("B5") <> 0 Then
Wbk2.Sheets("Somme").Range("B5").Copy _
Destination:=Wbk1.ActiveSheet.Range("D" & Num_Lig)
End If
If Range("B6") <> 0 Then
Wbk2.Sheets("Somme").Range("B6").Copy _
Destination:=Wbk1.ActiveSheet.Range("F" & Num_Lig)
End If
If Range("B7") <> 0 Then
Wbk2.Sheets("Somme").Range("B7").Copy _
Destination:=Wbk1.ActiveSheet.Range("H" & Num_Lig)
End If
If Range("B8") <> 0 Then
Wbk2.Sheets("Somme").Range("B8").Copy _
Destination:=Wbk1.ActiveSheet.Range("E" & Num_Lig)
End If
If Range("C9") <> 0 Then
Wbk2.Sheets("Somme").Range("C9").Copy _
Destination:=Wbk1.ActiveSheet.Range("L" & Num_Lig)
End If
If (Range("C10") <> 0 And Range("B10") <> 0) Then
Range("B10") = Range("B10") * (-1)
Range("B10").Select
With Selection.Font
.ColorIndex = 3
End With
Wbk1.ActiveSheet.Range("N" & Num_Lig) = Wbk2.Sheets("Somme").Range("B10").Value + Wbk2.Sheets("Somme").Range("C10").Value
Else
If Range("B10") <> 0 Then
Range("B10") = Range("B10") * (-1)
Range("B10").Select
With Selection.Font
.ColorIndex = 3
End With
Wbk2.Sheets("Somme").Range("B10").Copy _
Destination:=Wbk1.ActiveSheet.Range("N" & Num_Lig)
Else
If Range("C10") <> 0 Then
Wbk2.Sheets("Somme").Range("C10").Copy _
Destination:=Wbk1.ActiveSheet.Range("N" & Num_Lig)
End If
End If
End If
Wbk1.Activate
Cells.Select
Cells.EntireColumn.AutoFit
' Message d'erreurs si problème d'ouverture du fichier
Exit Sub 'Arrête la procédure pour éviter le message
MsgErreurs:
MsgBox "Il faut sélectionner un fichier"
End Sub |
Partager