I would like to create a macro that will sum the unit column base by Product & DC. It will populate out the same product name, code with dc code and code without. Base on the code given I try to modify the code but fail when I added the column Sales Person in front, Date & Country, as output I want to show the data with the latest date and country and the new data in the column.

```
Sub Button1_Click()

   ' Define constants.
    Const sName As String = "Sheet1"
    Const sFirstCellAddress As String = "A2"
    Const dName As String = "Sheet2"
    Const dFirstCellAddress As String = "A1"

    ' Define workbook.
    Dim wb As Workbook: Set wb = ThisWorkbook

    ' Write values from Source Range to Data Array.
    Dim LastRow As Long
    Dim Data As Variant
    With wb.Worksheets(sName).Range(sFirstCellAddress)
        LastRow = .Worksheet.Cells(.Worksheet.Rows.Count, .Column).End(xlUp).Row
        Data = .Resize(LastRow - .Row + 1, 8) 'modify

    End With

    ' Write unique values from Data Array to Unique Dictionary.
    Dim dict As Object: Set dict = CreateObject("Scripting.Dictionary")
    dict.CompareMode = vbTextCompare
    Dim arr(1 To 2) As Variant
    Dim Key As Variant
    Dim cArr As Variant
    Dim r As Long
    For r = 1 To UBound(Data, 1)
        Key = Data(r, 1)
        If Not IsError(Key) Then
            If Not dict.Exists(Key) Then
                dict.Add Key, arr
            End If
            If Data(r, 2) = 0 Then
                cArr = dict(Key)
                cArr(2) = cArr(2) + Data(r, 3)
                dict(Key) = cArr
            Else
                cArr = dict(Key)
                cArr(1) = cArr(1) + Data(r, 3)
                dict(Key) = cArr
            End If
        End If
        Key2 = Data(r, 4)
        Key3 = Data(r, 5)
        Key4 = Data(r, 6)
        Key5 = Data(r, 7)
        Key6 = Data(r, 8)
    Next r

    ' Write values from Unique Dictionary to Result Array.
    Dim rCount As Long: rCount = dict.Count + 1
    Dim Result As Variant: ReDim Result(1 To rCount, 1 To 8) 'change from 3 to 8
    Result(1, 1) = "SalesPerson"
    Result(1, 2) = "Company"
    Result(1, 3) = "Product"
    Result(1, 4) = "Unit With DC Code"
    Result(1, 5) = "Unit Without DC Code"
    Result(1, 6) = "Date"
    Result(1, 7) = "Country"
    Result(1, 8) = "Grade"

    If rCount > 1 Then
        r = 1
        For Each Key In dict.Keys
            r = r + 1
            Result(r, 1) = Key1
            Result(r, 2) = Key2
            Result(r, 3) = Key3
            Result(r, 4) = CLng(dict(Key)(1))
            Result(r, 5) = CLng(dict(Key)(2))
            Result(r, 6) = Key4
            Result(r, 7) = Key5
            Result(r, 8) = Key6
        Next Key
    End If

    ' Write values from Result Array to Destination Range.
    With wb.Worksheets(dName).Range(dFirstCellAddress).Resize(, 5)
        .Resize(rCount).Value = Result
        ' Delete below.
        '.Resize(.Worksheet.Rows.Count - .Row - rCount + 1) _
            .Offset(rCount).ClearContents
    End With

MsgBox ("Done")

End Sub

```

| SalesPerson | Company | Product | DC | Unit | Date | Country | Grade |
| --- | --- | --- | --- | --- | --- | --- | --- |
| JOHN | TPP | ABC |  | 2 | 12-Feb | MY | AA |
| JOHN | TPP | ABC | 1234 | 4 | 13-Feb | MY | AA |
| JOHN | TPP | ABC | 1234 | 4 | 14-Feb | US | AA |
| JOHN | PEN | DEF | 5678 | 2 | 12-Feb | US | AA |
| JOHN | PEN | DEF | 5678 | 2 | 18-Feb | MY | AA |
| JOHN | PKG | GHI | 9012 | 2 | 16-Feb | UK | AA |

I want to the output in another sheets as below:-

| SalesPerson | Company | Product | Unit with DC Code | Unit Without DC Code | Date | Country | Grade |
| --- | --- | --- | --- | --- | --- | --- | --- |
| JOHN | TPP | ABC | 6 | 2 | 14-Feb | US | AA |
| JOHN | PEN | DEF | 4 |  | 18-Feb | MY | AA |
| JOHN | PKG | GHI | 2 |  | 16-Feb | UK | AA |