Bonjour,
Je me suis amusé à produire un autre résultat (j'ai vérifié que j'allais pas fournir la même chose que gmb, c'est déjà arrivé ! )
Function NumLC(LC, ByVal n As Integer) As Integer
Dim i%
For i = 1 To UBound(LC)
If LC(i) = n Then NumLC = i: Exit For
Next i
End Function
Function Ordonner(LC)
Dim Ord, i%, j%
Ord = Split(LC, ";")
For i = 1 To UBound(Ord) - 1
If Ord(i) <> "" Then
For j = i + 1 To UBound(Ord)
If Ord(j) = Ord(i) Then Ord(j) = "@"
Next j
End If
Next i
Ord = Split(Replace(Join(Ord, ";"), ";@", ""), ";")
For i = 1 To UBound(Ord) - 1
For j = i + 1 To UBound(Ord)
If Ord(j) < Ord(i) Then
Ord(0) = Ord(j): Ord(j) = Ord(i): Ord(i) = Ord(0)
End If
Next j
Next i
Ord(0) = ""
Ordonner = Ord
End Function
Sub ExtracBesoins()
Dim T(), Lgn, Col, V, OL, OC, n%, k%, i%, c As Range
With Worksheets("Feuil1")
n = .Cells(.Rows.Count, 1).End(xlUp).Row
k = .Cells(1, Columns.Count).End(xlToLeft).Column
For Each c In .Range(.Cells(2, 2), .Cells(n, k))
If c = -1 Or c = -2 Then
Lgn = Lgn & ";" & c.Row
Col = Col & ";" & c.Column
V = V & ";" & c.Value
End If
Next c
OL = Ordonner(Lgn)
OC = Ordonner(Col)
Lgn = Split(Lgn, ";")
Col = Split(Col, ";")
V = Split(V, ";")
ReDim T(UBound(OL), UBound(OC))
T(0, 0) = "Tableau besoins formations 6-12 mois"
For i = 1 To UBound(V)
n = NumLC(OL, CInt(Lgn(i)))
k = NumLC(OC, CInt(Col(i)))
T(n, 0) = .Cells(CInt(Lgn(i)), 1)
T(0, k) = .Cells(1, CInt(Col(i)))
T(n, k) = CInt(V(i))
Next i
End With
With Worksheets("Feuil2").Range("A1")
.CurrentRegion.Clear
With .Resize(UBound(T, 1) + 1, UBound(T, 2) + 1)
.Value = T
.Columns.AutoFit
End With
End With
End Sub
Macro qui utilise deux fonctions pour les calculs annexes et produit un tableau... Je me suis inspiré de gmb en la faisant déclencher par Activate (mais elle peut l'être indépendamment).
Cordialement.