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
| Private Sub cancel_Click()
Unload Me
End Sub
Private Sub lancer_Click()
If DateImport.Text = "" Or Not IsDate(DateImport.Text) Then
MsgBox "Il faut impérativement saisir une date valide!", vbCritical, "Erreur d'importation"
DateImport.SetFocus
Exit Sub
End If
LireLeFichierTexte (Chemin.Text)
End Sub
Private Sub CommandButton1_Click()
'Declarer la varibale FileDialog object.
Dim fd As FileDialog
'Creation de l'objet FileDialog object comme File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Declarer une variable string qui va contenir le chemin du fichier séléctionné
Dim vrtSelectedItem As String
'Un seul fichier à sélectionner par choix
fd.AllowMultiSelect = True
'Titre à affecter à la boite de dialogue de sélection du fichier
fd.Title = "Parcourir le fichier de sortie de jihane :)"
'Ajouter le filtre pour n'inclure que les fichiers .txt
fd.Filters.Add "Fichers Textes", "*.txt", 1
'Sets the initial file filter to number 2.
fd.FilterIndex = 1
'Use a With...End With block to reference the FileDialog object.
With fd
If .Show = -1 Then
'Affecter dans la varibale string le chemin
vrtSelectedItem = .SelectedItems(1)
'affecter le chemin dnas la zone de texte c'est pas obligatoire mais juste pour me rassurer que c'est le bon chemin
Chemin.Text = vrtSelectedItem
Else
MsgBox "Aucun fichier sélectionné", vbInformation, "Erreur d'import"
End If
End With
'destruction de la variable fd
Set fd = Nothing
End Sub
Private Sub LireLeFichierTexte(CheminFichiertxt As String)
'variable à ne pas accorder attention
Dim intFic As Integer
'variable qui contiendera une ligne entière
Dim strLigne As String
'pas d'importance
intFic = FreeFile
'ouverture du fichier
Open CheminFichiertxt For Input As intFic
'Variable qui contiendera le nombre de ligne insérée
Dim i As Integer
'elle est initialisée à 2 pour commencer l'ecriture dans la 2ieme ligne
i = 2
Dim j As Integer
j = 0
Dim k As Integer
k = 0
Dim TableauFinalParCompte(999, 2)
Dim TableauFinalParRubrique(999, 2)
While Not EOF(intFic)
'lire la ligne et la stocker dans strligne
Line Input #intFic, strLigne
If InStr(1, strLigne, "#") Then
'puisque la ligne contient beacoup d'info elle doit etre stockée dnas un tableau délimité par espace
Do While InStr(1, strLigne, " ") > 0
strLigne = Replace(strLigne, " ", " ")
Loop
Dim ligneEntiere As Variant
'Diviser la ligne séparée par tabulation
ligneEntiere = Split(strLigne, " ")
'variable qui contiendera le numéro de compte
Dim NumeroDeCompte As Variant
NumeroDeCompte = Split(ligneEntiere(), " ")
Dim SoldeDeFinApresVirgule As Variant
Dim SoldeDeFinAvantVirgule As Variant
Dim SoldeDeFin As Variant
If IsNumeric(ligneEntiere(4)) Then
SoldeDeFin = ligneEntiere(4)
Else
SoldeDeFin = ligneEntiere(5)
End If
Dim PosDerniereVirguleSolde As Integer
PosDerniereVirguleSolde = InStrRev(SoldeDeFin, ".")
If PosDerniereVirguleSolde = 0 Then
SoldeDeFin = SoldeDeFin
Else
SoldeDeFinApresVirgule = Mid(SoldeDeFin, PosDerniereVirguleSolde + 1, 2)
SoldeDeFinAvantVirgule = Mid(SoldeDeFin, 1, PosDerniereVirguleSolde - 1)
SoldeDeFinAvantVirgule = Replace(SoldeDeFinAvantVirgule, ",", "")
SoldeDeFinAvantVirgule = Replace(SoldeDeFinAvantVirgule, " ", "")
SoldeDeFin = SoldeDeFinAvantVirgule & "," & SoldeDeFinApresVirgule
End If
If NumeroDeCompte(1) = TableauFinalParCompte(j, 0) Or TableauFinalParCompte(j, 0) = "" Then
TableauFinalParCompte(j, 0) = NumeroDeCompte(1)
TableauFinalParCompte(j, 1) = CDbl(TableauFinalParCompte(j, 1)) + CDbl(SoldeDeFin)
Else
j = j + 1
'ReDim Preserve TableauFinalParCompte(0 To j, 0 To 2)
TableauFinalParCompte(j, 0) = NumeroDeCompte(1)
TableauFinalParCompte(j, 1) = CDbl(SoldeDeFin)
End If
If Rubrique = TableauFinalParRubrique(k, 0) Or TableauFinalParRubrique(k, 0) = "" Then
TableauFinalParRubrique(k, 0) = Rubrique
TableauFinalParRubrique(k, 1) = CDbl(TableauFinalParRubrique(k, 1)) + CDbl(SoldeDeFin)
Else
k = k + 1
'ReDim Preserve TableauFinalParCompte(0 To j, 0 To 2)
TableauFinalParRubrique(k, 0) = Rubrique
TableauFinalParRubrique(k, 1) = CDbl(SoldeDeFin)
End If
i = i + 1
End If
'pas d'importance
Me.Repaint
Wend
'fermeture du fichier
Close intFic
For Each F In Sheets
If UCase(F.Name) Like "BASE BALANCE" Then
F.Activate
Exit For
End If
Next F
'Si à la sortie de la dernière boucle la feuille active n'est pas "BASE BALANCE" un message d'erreur doit s'affiché
If F.Name <> "BASE BALANCE" Then
MsgBox "Il n'existe aucune feuille avec le nom BASE BALANCE! Fin des traitements", vbCritical, "Reporting"
Exit Sub
End If
Dim NumeroDeColonne As Integer
NumeroDeColonne = 1
Dim der_col As Long
der_col = Range("IV1").End(xlToLeft).Column + 1
For NumeroDeColonne = 1 To der_col
Cells(1, NumeroDeColonne).Select
If CStr(Cells(1, NumeroDeColonne).Value) = CStr(DateImport.Text) Then
Exit For
End If
Next
If NumeroDeColonne = der_col + 1 Then
Range(Cells(1, NumeroDeColonne), Cells(1, NumeroDeColonne + 1)).Select
Range(Cells(1, NumeroDeColonne), Cells(1, NumeroDeColonne + 1)).Merge
ActiveCell.Select
ActiveCell.Value = DateImport.Text
Range(Cells(1, NumeroDeColonne - 2), Cells(1, NumeroDeColonne - 1)).Select
Selection.Copy
Range(Cells(1, NumeroDeColonne), Cells(1, NumeroDeColonne + 1)).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Cells(2, NumeroDeColonne).Value = "solde Bilan"
Cells(2, NumeroDeColonne + 1).Value = "encours Bilan"
Cells(2, NumeroDeColonne - 2).Select
Selection.Copy
Cells(2, NumeroDeColonne).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Cells(2, NumeroDeColonne - 1).Select
Selection.Copy
Cells(2, NumeroDeColonne + 1).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End If
Dim CompteurDeLigne As Integer
CompteurDeLigne = 0
For CompteurDeLigne = 3 To 999
Dim CompteurDeTableau As Integer
CompteurDeTableau = 0
For CompteurDeTableau = 0 To 999
If Trim(Cells(CompteurDeLigne, 2)) = TableauFinalParCompte(CompteurDeTableau, 0) Then
Cells(CompteurDeLigne, NumeroDeColonne) = TableauFinalParCompte(CompteurDeTableau, 2)
Cells(CompteurDeLigne, NumeroDeColonne + 1) = TableauFinalParCompte(CompteurDeTableau, 1)
Exit For
End If
Next
Next
For Each F In Sheets
If UCase(F.Name) Like "ER" Then
F.Activate
Exit For
End If
Next F
'Si à la sortie de la dernière boucle la feuille active n'est pas "BASE BALANCE" un message d'erreur doit s'affiché
If F.Name <> "ER" Then
MsgBox "Il n'existe aucune feuille avec le nom ER! Fin des traitements", vbCritical, "Reporting"
Exit Sub
End If
Dim NumeroDeColonneER As Integer
NumeroDeColonneER = 1
Dim der_colER As Long
der_colER = Range("IV1").End(xlToLeft).Column + 1
For NumeroDeColonneER = 1 To der_colER
Cells(1, NumeroDeColonneER).Select
If CStr(Cells(1, NumeroDeColonneER).Value) = CStr(DateImport.Text) Then
Exit For
End If
Next
If NumeroDeColonneER = der_colER + 1 Then
Range(Cells(1, NumeroDeColonneER), Cells(1, NumeroDeColonneER + 1)).Select
Range(Cells(1, NumeroDeColonneER), Cells(1, NumeroDeColonneER + 1)).Merge
ActiveCell.Select
ActiveCell.Value = DateImport.Text
Range(Cells(1, NumeroDeColonneER - 2), Cells(1, NumeroDeColonneER - 1)).Select
Selection.Copy
Range(Cells(1, NumeroDeColonneER), Cells(1, NumeroDeColonneER + 1)).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Cells(2, NumeroDeColonneER).Value = "solde Bilan"
Cells(2, NumeroDeColonneER + 1).Value = "encours Bilan"
Cells(2, NumeroDeColonneER - 2).Select
Selection.Copy
Cells(2, NumeroDeColonneER).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Cells(2, NumeroDeColonneER - 1).Select
Selection.Copy
Cells(2, NumeroDeColonneER + 1).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End If
Dim CompteurCell As Integer
CompteurCell = 3
For CompteurCell = 3 To 63
Dim SoldeDeFinParRubrique As Double
SoldeDeFinParRubrique = 0
Dim Rubriques As Variant
Rubriques = Split(Cells(CompteurCell, 3), "+")
Dim CompteurTableauRubrique As Integer
CompteurTableauRubrique = 0
For CompteurRubrique = 0 To UBound(Rubriques)
Dim CompteurRubrique1 As Integer
CompteurRubrique1 = 0
For CompteurTableauRubrique1 = 0 To 999
If TableauFinalParRubrique(CompteurTableauRubrique1, 0) = Rubriques(CompteurRubrique) Then
SoldeDeFinParRubrique = SoldeDeFinParRubrique + CDbl(TableauFinalParRubrique(CompteurTableauRubrique1, 1))
Exit For
End If
Next
Next
Cells(CompteurCell, NumeroDeColonneER).Value = SoldeDeFinParRubrique
Next
MsgBox "fin"
Unload Me
End Sub
Private Sub TextBox2_Change()
NumberFormat = m / d / yyyy
End Sub
Private Sub UserForm_Initialize()
If acces = 0 Then
Unload Me
'ActiveWorkbook.Close (False)
End If
End Sub |
Partager