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
| Option Explicit
Private Matrice1() As Variant
Private Matrice2() As Variant
Private LigneDeTitre As Long
Private DerniereLigne As Long
Private I As Long
Private J As Long
Private Cellule As Range
Private ContenuMatrice1Avant As String
Private ContenuMatrice1Apres As String
Sub ChargementMatrice()
' Chargement de la matrice 1 à deux dimensions (X colonnes, Y lignes)
LigneDeTitre = 1
DerniereLigne = Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
Range(Cells(LigneDeTitre + 1, 1), Cells(DerniereLigne, 1)).Select
ReDim Matrice1(1, Selection.Count - 1) ' X = deux colonnes 0 et 1
I = 0
ContenuMatrice1Avant = "Matrice 1 avant" & Chr(10)
For Each Cellule In Selection
Matrice1(0, I) = Cellule
Matrice1(1, I) = Cellule.Offset(0, 1)
ContenuMatrice1Avant = ContenuMatrice1Avant & Chr(10) & " " & Matrice1(0, I)
I = I + 1
Next Cellule
' La matrice est chargée
Call ModificationMatrice1
MsgBox (ContenuMatrice1Avant & Chr(10) & Chr(10) & Chr(10) & ContenuMatrice1Apres)
End Sub
Sub ModificationMatrice1()
J = 0
For I = LBound(Matrice1, 2) To UBound(Matrice1, 2)
Select Case Matrice1(0, I)
Case "Désignation de l'objet", "Société", "Nature comptable", "Désignation nature comptable", "CCS", "Objet partenaire"
ReDim Preserve Matrice2(1, J)
Matrice2(0, J) = Matrice1(0, I)
Matrice2(1, J) = Matrice1(1, I)
J = J + 1
End Select
Next I
ReDim Matrice1(1, UBound(Matrice2, 2))
Matrice1 = Matrice2
ContenuMatrice1Apres = "Matrice 1 après" & Chr(10)
For I = LBound(Matrice1, 2) To UBound(Matrice1, 2)
ContenuMatrice1Apres = ContenuMatrice1Apres & Chr(10) & " " & Matrice1(0, I)
Next I
End Sub |
Partager