Private Sub Worksheet_Activate()
Dim ncol%, colref%, x$, w As Worksheet, t, i&, n&, rest(), j%
ncol = 10 'nombre de colonnes des tableaux source
colref = IIf([B1] = "Cuve", 1, 7)
x = IIf([B1] = "", "", IIf([B1] = "Cuve", "C" & [B2], "*" & [B3] & "*"))
Application.ScreenUpdating = False
Rows("2:3").Hidden = False
If [B1] = "Cuve" Then Rows(3).Hidden = True _
Else: If [B1] = "Code" Then Rows(2).Hidden = True
Rows("6:" & Rows.Count).Delete 'RAZ
For Each w In Worksheets
If w.Name <> Me.Name Then
t = w.[A1].CurrentRegion.Resize(, ncol).Value2
For i = 2 To UBound(t)
If x = "" Or t(i, colref) Like x Then
n = n + 1
ReDim Preserve rest(1 To ncol + 1, 1 To n)
rest(1, n) = w.Name
For j = 1 To ncol
rest(j + 1, n) = t(i, j)
Next j
End If
Next i
End If
Next
'---restitution, tri et bordures---
If n = 0 Then Exit Sub
With [A6].Resize(n, ncol + 1)
.Value = Application.Transpose(rest)
.Sort .Columns(1), xlAscending, Header:=xlNo
For j = 7 To 10
.Borders(j).Weight = xlMedium 'contour
Next j
.Borders(xlInsideVertical).Weight = xlThin
.Borders(xlInsideHorizontal).Weight = xlHairline
End With
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [B1:B3]) Is Nothing Then Worksheet_Activate
End Sub