Hello Yasser,
I have added this macro to the attached workbook. This uses the Dictionary and Variant Arrays to hold the Range data. When possible, it is easier and faster to manipulate arrays than objects.
Here is the macro...
Option Explicit
Sub Macro1()
Dim Cell As Range
Dim Data As Variant
Dim Dict As Object
Dim Item As Variant
Dim Key As Variant
Dim Rng As Range
Dim RngBeg As Range
Dim RngEnd As Range
Dim Wks As Worksheet
Dim x As Long
Dim y As Long
Set Wks = ThisWorkbook.Worksheets("Sheet1")
Set RngBeg = Wks.Range("A2:D2")
Set RngEnd = Wks.Cells(Rows.Count, RngBeg.Column).End(xlUp)
If RngEnd.Row < RngBeg.Row Then Exit Sub
Set Rng = Wks.Range(RngBeg, RngEnd)
Set Dict = CreateObject("Scripting.Dictionary")
Dict.CompareMode = vbTextCompare
For Each Cell In Rng.Columns(1).Cells
Key = Trim(Cell)
Item = Cell.Resize(1, Rng.Columns.Count).Value
If Not Dict.Exists(Key) Then
Dict.Add Key, Item
Else
' To increase the rows in the 2-D array it must first be transposed.
' Only the last dimension of an array can be resized.
Data = Application.Transpose(Dict(Key))
x = UBound(Data, 1)
y = UBound(Data, 2) + 1
ReDim Preserve Data(1 To x, 1 To y)
' Transposing the array a second time restores the original order.
Data = Application.Transpose(Data)
' Load the new data.
For x = 1 To UBound(Item, 2)
Data(y, x) = Item(1, x)
Next x
' Save the Data.
Dict(Key) = Data
End If
Next Cell
Set Rng = Wks.Range("G2")
For Each Item In Dict.Items
x = UBound(Item, 1)
y = UBound(Item, 2)
Rng.Resize(x, y).Value = Item
Set Rng = Rng.Offset(x, 0)
Next Item
End Sub