Private Sub Worksheet_Activate()
Dim etat, UR As Range, c As Range, cc As Range, P As Range, n&
Application.ScreenUpdating = False
etat = Application.CopyObjectsWithCells
Application.CopyObjectsWithCells = False 'les objets ne sont pas copiés
Set UR = Me.UsedRange
UR.Copy UR.Offset(UR.Rows.Count) 'copie pour mémoriser les formats
UR.ClearFormats 'efface les formats
For Each c In Sheets("Listes").[D2:D1000]
If c <> "" Then
Set cc = UR.Find(c, , xlValues, xlWhole)
If cc Is Nothing Then
MsgBox c & " pas trouvé"
Else
Set P = Union(IIf(P Is Nothing, cc, P), cc)
n = n + 1
End If
End If
Next
UR.Offset(UR.Rows.Count).Copy UR 'restitue les formats
UR.Offset(UR.Rows.Count).Delete xlUp
If n Then P.Select: MsgBox n & " éléments trouvés"
Application.CopyObjectsWithCells = etat
End Sub
Ma macro est une macro évènementielle, elle doit être placée dans le code de la feuillr "Plan".Si je comprends bien je dois copier cette macro dans l'éditeur VBA sur la feuille "Plan" ?
Sub Grouper3()
Dim c As Range, P As Range
On Error Resume Next 'si aucune SpecialCell
For Each c In Cells.SpecialCells(xlCellTypeConstants)
If IsNumeric(CStr(c)) Or IsNumeric(Mid(c, 2)) Then Set P = Union(IIf(P Is Nothing, c.MergeArea, P), c.MergeArea)
Next
P.Select
End Sub
Private Sub Worksheet_Activate()
Dim c As Range, P As Range
On Error Resume Next 'si aucune SpecialCell
For Each c In Cells.SpecialCells(xlCellTypeConstants)
If IsNumeric(CStr(c)) Or IsNumeric(Mid(c, 2)) Then Set P = Union(IIf(P Is Nothing, c.MergeArea, P), c.MergeArea)
Next
P.Select
End Sub