Merci franchement ça colle, ça demande un peu de recherche et apprentissage de ma part car je ne connais que très peu le vba
On est d'accord c'est bcp mieux que mes multiples formules de recherche et calculs ?
Si tu as un petit conseil par rapport à l'ergonomie ou quoi je suis à l'écoute!
je me colle le module
Option Explicit
Sub Report()
Application.ScreenUpdating = False
Dim wbS As Workbook, wbC As Workbook
Dim shS As Worksheet, shC As Worksheet
Dim dl As Integer, i As Integer, numScie As Integer
Dim tmp()
Dim lo As ListObject
Dim dico1 As Object
Dim dico2 As Object
Dim cle As Variant, x As Variant, y As Variant
Set dico1 = CreateObject("Scripting.Dictionary")
Set dico2 = CreateObject("Scripting.Dictionary")
Set wbS = Workbooks("trg-suivi-scies.xlsx")
Set wbC = Workbooks("planning-prods22 yal v1.xlsm")
Set shC = wbC.Sheets("TRG prepas-bois")
Set lo = shC.ListObjects("tb_report")
If Sheets("TRG prepas-bois").ListObjects("tb_report").ListRows.Count > 0 Then
Range("tb_report").Delete
End If
For Each shS In wbS.Sheets
If Left(shS.Name, 10) = "Suivi Scie" Then
numScie = Right(shS.Name, Len(shS.Name) - 11)
dl = shS.Cells(Rows.Count, 1).End(xlUp).Row
If dl > 5 Then
tmp = shS.Range("A6:W" & dl).Value2
For i = 1 To UBound(tmp)
If tmp(i, 1) <> "" Then
If IsError(tmp(i, 21)) Then tmp(i, 21) = "nc"
dico1(tmp(i, 1) & tmp(i, 5)) = dico1(tmp(i, 1) & tmp(i, 5)) & "|" & numScie
dico2(tmp(i, 1) & tmp(i, 5)) = dico2(tmp(i, 1) & tmp(i, 5)) & "|" & tmp(i, 21)
End If
Next i
End If
End If
Next shS
ReDim tmp(1 To dico1.Count, 1 To 8)
dl = 1
For Each cle In dico1.keys
x = Split(dico1.Item(cle), "|")
y = Split(dico2.Item(cle), "|")
For i = 1 To UBound(x)
tmp(dl, 1) = CDbl(Left(cle, 5))
tmp(dl, 2) = Right(cle, Len(cle) - 5)
If IsNumeric(y(i)) = True Then
tmp(dl, CInt(x(i)) + 2) = CDbl(y(i))
Else
tmp(dl, CInt(x(i)) + 2) = y(i)
End If
Next i
dl = dl + 1
Next cle
Range("tb_report").Resize(UBound(tmp), UBound(tmp, 2)) = tmp
Range("tb_report[Moy TRG]").FormulaR1C1 = "=AVERAGE(tb_report[@[TRG %scie1]:[TRG %scie5]])"
Application.ScreenUpdating = True
End Sub