Stacy Rueda
Board Regular
- Joined
- Jun 23, 2016
- Messages
- 87
Hi guys, Thank you in advance to those who can help me. I know there's same issue with mine but I can't find the exactly the same because what i found almost on the internet is just only two columns, but in my case I have four columns. I also found code like below, but like I've said this is just applicable for two columns only.
And this is what I want in my excel: please see picture
<colgroup><col><col span="2"><col></colgroup><tbody>
</tbody>
<colgroup><col><col><col><col></colgroup><tbody>
</tbody>
Code:
Option Explicit
Sub Main()
Dim Source As Worksheet: Set Source = ThisWorkbook.Worksheets("Sheet1")
Dim Destination As Worksheet: Set Destination = ThisWorkbook.Worksheets("Sheet3")
Dim Records As Object: Set Records = CreateObject("Scripting.Dictionary")
Dim Data As Variant
Dim Index As Long
Dim Row As Integer: Row = 1
Data = Source.Range("A1", "B" & Source.Rows(Source.UsedRange.Rows.Count).Row).Value2
For Index = LBound(Data, 1) To UBound(Data, 1)
If Records.Exists(Data(Index, 1)) Then
Destination.Cells(Records(Data(Index, 1)), 2).Value2 = Destination.Cells(Records(Data(Index, 1)), 2).Value2 & ", " & Data(Index, 2)
Else
Records.Add Data(Index, 1), Row
Destination.Cells(Row, 1).Value2 = Data(Index, 1)
Destination.Cells(Row, 2).Value2 = Data(Index, 2)
Row = Row + 1
End If
Next Index
And this is what I want in my excel: please see picture
FROM | |||
Employee | Location | Description | Quantity |
Susan | P1 | Chef | 1 |
Susan | P2 | Chef | 1 |
Susan | P3 | Chef | 1 |
Mart | P0 | Washer | 2 |
Ed | E3 | Cleaner | 10 |
Ed | E4 | Cleaner | 10 |
Ram | G1 | Preparation | 45 |
Ram | G4 | Preparation | 45 |
Ram | G7 | Preparation | 45 |
Ram | G8 | Preparation | 45 |
<colgroup><col><col span="2"><col></colgroup><tbody>
</tbody>
FROM | |||
Employee | Location | Description | Quantity |
Susan | P1,P2,P3 | Chef | 3 |
Mart | P0 | Washer | 2 |
Ed | E3,E4 | Cleaner | 20 |
Ram | G1,G4,G7,G8 | Preparation | 180 |
<colgroup><col><col><col><col></colgroup><tbody>
</tbody>