re,
bon, on peut emmener un cheval à l'eau, mais on ne peut pas le forcer à boire ...
ceci vous donne une reduction de 29%, cela vaut la peine ? Avec l'autre methode c'était 37%
Sub Supprimer()
Dim WB As Workbook, WB1 As Workbook, WB2, SH, aAddress, LO
Set dict = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
t = Timer
On Error Resume Next
Set WB1 = Workbooks("classeur 1.xlsx")
If WB1 Is Nothing Then Set WB1 = Workbooks.Open(ThisWorkbook.Path & "\classeur-1.xlsx")
If WB1 Is Nothing Then MsgBox "erreur 1": Exit Sub
Set WB2 = Workbooks("classeur 2.xlsx")
If WB2 Is Nothing Then Set WB2 = Workbooks.Open(ThisWorkbook.Path & "\classeur-2.xlsx")
If WB2 Is Nothing Then MsgBox "erreur 2": Exit Sub
On Error GoTo 0
For iWB = 1 To 2
If iWB Mod 2 = 1 Then Set WB = WB1 Else Set WB = WB2
For Each SH In WB.Sheets
With SH.Range("B21").CurrentRegion
Set c = .Offset(32 - .Row).Resize(1)
c.FormulaR1C1 = "=TEXTJOIN("","",0,R21C:R30C)"
c.EntireColumn.Hidden = False
For Each c0 In c.Cells
If dict.exists(c0.Value) Then
b = True
Else
c0.EntireColumn.Hidden = True
dict(c0.Value) = vbEmpty
End If
Next
i1 = c.Columns.Count
If b Then c.SpecialCells(xlVisible).EntireColumn.Delete
c.EntireColumn.Hidden = False
i2 = c.Columns.Count
MsgBox "classeur : " & WB.Name & vbLf & "sheet : " & SH.Name & vbLf & Format(i1, "#,##0") & " colonnes >>> " & Format(i2, "#,##0") & " colonnes" & vbLf & Format(i2 / i1, "##.0%")
dict.RemoveAll
End With
Next
Next
WB1.Close 1
WB2.Close 1
Application.ScreenUpdating = True 'plus tard, on supprime ceci pour la vitesse !!!
End Sub