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
|
Sub Main()
'Définition de la structure du fichier
Dim ColDateMAJ As Integer
ColDateMAJ = ColonneCible(ThisWorkbook.Name, "Détail", "Date mise à jour", 1)
ThisWorkbook.Worksheets("Détail").Cells(2, ColDateMAJ) = Date
Dim ColType As Integer, ColDocumentAchat As Integer, ColPoste As Integer, ColArticle As Integer, ColTexteCommande As Integer
Dim ColDesignation As Integer, ColQuantite As Integer, ColUniteQuantite As Integer, ColValeur As Integer, ColOTP As Integer
Dim ColNatureComptable As Integer, ColDescriptionNatureComptable As Integer, ColDateComptable As Integer, ColPeriode As Integer
Dim ColDatePiece As Integer, ColUtilisateur As Integer, ColTexteEnTete As Integer, ColCommentaire As Integer, ColChapitre As Integer
Dim ColPieceRef As Integer
ColType = ColonneCible(ThisWorkbook.Name, "Détail", "Type", 1)
ColDocumentAchat = ColonneCible(ThisWorkbook.Name, "Détail", "Document d'achat", 1)
ColPoste = ColonneCible(ThisWorkbook.Name, "Détail", "Poste", 1)
ColArticle = ColonneCible(ThisWorkbook.Name, "Détail", "Article", 1)
ColTexteCommande = ColonneCible(ThisWorkbook.Name, "Détail", "Texte de la commande d'achat", 1)
ColDesignation = ColonneCible(ThisWorkbook.Name, "Détail", "Désignation", 1)
ColQuantite = ColonneCible(ThisWorkbook.Name, "Détail", "Quantité totale", 1)
ColUniteQuantite = ColonneCible(ThisWorkbook.Name, "Détail", "Unité de quantité", 1)
ColValeur = ColonneCible(ThisWorkbook.Name, "Détail", "Valeur", 1)
ColOTP = ColonneCible(ThisWorkbook.Name, "Détail", "Elément d'OTP", 1)
ColNatureComptable = ColonneCible(ThisWorkbook.Name, "Détail", "Nature comptable", 1)
ColDescriptionNatureComptable = ColonneCible(ThisWorkbook.Name, "Détail", "Descr.nat.comptable", 1)
ColDateComptable = ColonneCible(ThisWorkbook.Name, "Détail", "Date comptable", 1)
ColPeriode = ColonneCible(ThisWorkbook.Name, "Détail", "Période", 1)
ColDatePiece = ColonneCible(ThisWorkbook.Name, "Détail", "Date de la pièce", 1)
ColUtilisateur = ColonneCible(ThisWorkbook.Name, "Détail", "Utilisateur", 1)
ColTexteEnTete = ColonneCible(ThisWorkbook.Name, "Détail", "Texte d'en-tête de pièce", 1)
ColCommentaire = ColonneCible(ThisWorkbook.Name, "Détail", "Commentaires", 1)
ColChapitre = ColonneCible(ThisWorkbook.Name, "Détail", "Chapitre", 1)
ColPieceRef = ColonneCible(ThisWorkbook.Name, "Détail", "N° Pièce référénces", 1)
Dim import As String, Dos As String, NombreFichier As Integer, MonFichier As String, TypeClasseur As String
Dim MatriceEngage() As Variant, MatriceRealise() As Variant
'Identification du Dossier de stockage
import = Application.GetOpenFilename("Tous les Fichiers(*.*), *.*", , "Importation des Fichiers")
'Isoler l'adresse du dossier de stockage
Dos = CurDir(import)
'Vérifier nombre de fichier du Dossier
NombreFichier = NombreFichiers(Dos)
'Changement du répertoir par défaut
ChDir Dos
MonFichier = Dir("*.*")
While MonFichier <> ""
Set Classeur = Workbooks.Open(MonFichier)
TypeClasseur = Identification(Classeur)
If TypeClasseur = "Engagé" Then
MatriceEngage() = Classeur.Worksheets(1).Cells(1, 1).CurrentRegion.Value
ElseIf TypeClasseur = "Réalisé" Then
MatriceRealise() = Classeur.Worksheets(1).Cells(1, 1).CurrentRegion.Value
End If
Classeur.Close (False)
Set Classeur = Nothing
MonFichier = Dir()
Wend
'On obtient 2 matrices en mémoire cache
'on créé une 3ème matrice qui correspond au fichier actuel (avant suppression)
Dim MatriceSuiviBudget() As Variant
MatriceSuiviBudget() = ThisWorkbook.Worksheets("Détail").Cells(1, 1).CurrentRegion.Value
'on supprime les information budgétaire
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets("Détail")
.Range(.Cells(2, 1), .Cells(UBound(MatriceSuiviBudget, 1), UBound(MatriceSuiviBudget, 2))).Clear
'On engage l'enregistrement des informations
'On commence par les commandes réceptionnées
Dim ColReaPeriode As Integer, ColReaTexteCommande As Integer, ColReaDescriptionNatureComptable As Integer, ColReaValeur As Integer
Dim ColReaDate As Integer, ColReaOTP As Integer, ColReaDocumentAchat As Integer, ColReaDesignation As Integer, ColReaQuantite As Integer
Dim ColReaArticle As Integer, ColReaNatureComptable As Integer, ColReaPosteCommande As Integer, ColReaDateComptable As Integer
Dim ColReaDateSaisi As Integer, ColReaUtilisateur As Integer, ColReaTextePiece As Integer, ColReaUniteQuantite As Integer, ColReaPieceRef As Integer
ColReaPeriode = ColonneCible_Matrice(MatriceRealise, "Période", 1)
ColReaTexteCommande = ColonneCible_Matrice(MatriceRealise, "Texte de la commande d'achat", 1)
ColReaDescriptionNatureComptable = ColonneCible_Matrice(MatriceRealise, "Descr.nat.comptable", 1)
ColReaValeur = ColonneCible_Matrice(MatriceRealise, "Val./dev.état", 1)
ColReaDate = ColonneCible_Matrice(MatriceRealise, "Date de la pièce", 1)
ColReaOTP = ColonneCible_Matrice(MatriceRealise, "Elément d'OTP", 1)
ColReaDocumentAchat = ColonneCible_Matrice(MatriceRealise, "Document d'achat", 1)
ColReaDesignation = ColonneCible_Matrice(MatriceRealise, "Désignation", 1)
ColReaQuantite = ColonneCible_Matrice(MatriceRealise, "Quantité totale", 1)
ColReaUniteQuantite = ColonneCible_Matrice(MatriceRealise, "Unité de quantité", 1)
ColReaArticle = ColonneCible_Matrice(MatriceRealise, "Article", 1)
ColReaNatureComptable = ColonneCible_Matrice(MatriceRealise, "Nature comptable", 1)
ColReaPosteCommande = ColonneCible_Matrice(MatriceRealise, "Poste Commande", 1)
ColReaDateComptable = ColonneCible_Matrice(MatriceRealise, "Date comptable", 1)
ColReaDateSaisi = ColonneCible_Matrice(MatriceRealise, "Date de saisie", 1)
ColReaUtilisateur = ColonneCible_Matrice(MatriceRealise, "Utilisateur", 1)
ColReaTextePiece = ColonneCible_Matrice(MatriceRealise, "Texte d'en-tête de pièce", 1)
ColReaPieceRef = ColonneCible_Matrice(MatriceRealise, "Nº pièce référence", 1)
Dim i As Integer, j As Integer, k As Integer, m As Integer
Dim CommandeEnregistre As Boolean
CommandeEnregistre = False
Dim QuantiteReceptionnee() As Variant
ReDim QuantiteReceptionnee(UBound(MatriceRealise, 1), 4)
QuantiteReceptionnee(1, 1) = "Commande"
QuantiteReceptionnee(1, 2) = "Poste"
QuantiteReceptionnee(1, 3) = "Quantite"
QuantiteReceptionnee(1, 4) = "CommandeTrouvee"
j = 2
k = 1
For i = 2 To UBound(MatriceRealise, 1)
'Nécessaire de revoir le code car les quantités reçu sont inclus uniquement dans les classes 8
'on va créer une matrice sépcifique lié uniquement aux quantité
If Left(MatriceRealise(i, ColReaNatureComptable), 1) <> 8 Then
'on exclut les nature comptable de classe 8 pour les commandes réalisées
.Cells(j, ColType) = "Réalisé"
.Cells(j, ColDocumentAchat) = MatriceRealise(i, ColReaDocumentAchat)
.Cells(j, ColPoste) = MatriceRealise(i, ColReaPosteCommande)
.Cells(j, ColArticle) = MatriceRealise(i, ColReaArticle)
.Cells(j, ColTexteCommande) = MatriceRealise(i, ColReaTexteCommande)
.Cells(j, ColDesignation) = MatriceRealise(i, ColReaDesignation)
.Cells(j, ColQuantite) = MatriceRealise(i, ColReaQuantite)
.Cells(j, ColUniteQuantite) = MatriceRealise(i, ColReaUniteQuantite)
.Cells(j, ColValeur) = MatriceRealise(i, ColReaValeur)
.Cells(j, ColOTP) = MatriceRealise(i, ColReaOTP)
.Cells(j, ColNatureComptable) = MatriceRealise(i, ColReaNatureComptable)
.Cells(j, ColDescriptionNatureComptable) = MatriceRealise(i, ColReaDescriptionNatureComptable)
.Cells(j, ColDateComptable) = MatriceRealise(i, ColReaDateComptable)
.Cells(j, ColPeriode) = MatriceRealise(i, ColReaPeriode)
.Cells(j, ColDatePiece) = MatriceRealise(i, ColReaDate)
.Cells(j, ColUtilisateur) = MatriceRealise(i, ColReaUtilisateur)
.Cells(j, ColTexteEnTete) = MatriceRealise(i, ColReaTextePiece)
.Cells(j, ColPieceRef) = MatriceRealise(i, ColReaPieceRef) |
Partager