Bonsoir à tous,
Pas si évident ...à comprendre la demande .... et le but recherché
A tester :
Option Explicit
Sub test()
Dim a, b(), i As Long, j As Long, n As Long
Dim c() As Range, r As Range, x As Long, temp As String
a = Sheets("Feuil1").Range("b3").CurrentRegion.Value
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2) - 1)
For i = 1 To 5
b(1, i) = a(1, i + 1)
Next
For i = 2 To UBound(a, 2)
For j = 2 To UBound(a, 1)
If Not IsEmpty(a(j, i)) Then
x = a(j, i)
b(x + 1, i - 1) = a(j, 1)
End If
Next
Next
Application.ScreenUpdating = False
With Sheets("Feuil2")
.Cells.Clear
With .Cells(1)
With .Resize(UBound(b, 1), UBound(b, 2))
.Value = b
On Error Resume Next
.SpecialCells(4).Delete shift:=xlUp
On Error GoTo 0
With .CurrentRegion
.VerticalAlignment = xlCenter
.Borders(xlInsideVertical).Weight = xlThin
.Borders(xlInsideHorizontal).Weight = xlThin
.BorderAround Weight:=xlThin
With .Rows(1)
.Interior.ColorIndex = 6
End With
For Each r In .Cells
If temp <> r.Value Then
n = n + 1
ReDim Preserve c(1 To n)
Set c(n) = r: temp = r.Value
Else
Set c(n) = Union(c(n), r)
End If
Next
End With
End With
Application.DisplayAlerts = False
For i = 1 To n
With c(i)
.Merge
.HorizontalAlignment = xlCenter
End With
Next
Application.DisplayAlerts = True
End With
End With
Application.ScreenUpdating = True
End Sub
klin89