Concatenate and Sum VBA Macro

ukbulldog001

New Member
Joined
Jul 8, 2015
Messages
23
Office Version
  1. 2021
Platform
  1. Windows
Please help in providing macro to concatenate and sum as below table.
Below table starts from A2 to C9 (i'm leaving first row blank to write main header.)

Customer Part NumberReference DesignatorCount
91814232C3391
91832745MN281
91832745MN71
91835171MA21
91835171MA261
91839847MA401
91840078MX11

Need the result to be like below table
Below table is the same worksheet from E2 to G7
although header will already be there.

Customer Part NumberReference DesignatorCount
91814232C3391
91832745MN28, MN72
91835171MA2, MA262
91839847MA401
91840078MX11

the number of rows is not limited...
thanks in advance.
 

Attachments

  • Concatenate and Sum.JPG
    Concatenate and Sum.JPG
    49.6 KB · Views: 4

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
This could also be done with a formula, what version of Excel do you use?
 
Upvote 0
Hi
Try
VBA Code:
Sub test()
    Dim a, w
    Dim i&
        a = Cells(1).CurrentRegion
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If Not .exists(a(i, 1)) Then
                .Add a(i, 1), Array(a(i, 1), a(i, 2), 1)
            Else
                w = .Item(a(i, 1))
                w(1) = w(1) & "," & a(i, 2): w(2) = w(2) + 1
                .Item(a(i, 1)) = w
            End If
        Next
        Range("E2").Resize(.Count, 3) = Application.Index(.items, 0, 0)
    End With
End Sub
 
Upvote 0
Ignore the first one and try
VBA Code:
Sub test()
    Dim a, w
    Dim i&
        a = Cells(2, 1).CurrentRegion
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If Not .exists(a(i, 1)) Then
                .Add a(i, 1), Array(a(i, 1), a(i, 2), 1)
            Else
                w = .Item(a(i, 1))
                w(1) = w(1) & "," & a(i, 2): w(2) = w(2) + 1
                .Item(a(i, 1)) = w
            End If
        Next
        Range("E1").Resize(.Count, 3) = Application.Index(.items, 0, 0)
    End With
End Sub
 
Upvote 0
Ignore the first one and try
VBA Code:
Sub test()
    Dim a, w
    Dim i&
        a = Cells(2, 1).CurrentRegion
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If Not .exists(a(i, 1)) Then
                .Add a(i, 1), Array(a(i, 1), a(i, 2), 1)
            Else
                w = .Item(a(i, 1))
                w(1) = w(1) & "," & a(i, 2): w(2) = w(2) + 1
                .Item(a(i, 1)) = w
            End If
        Next
        Range("E1").Resize(.Count, 3) = Application.Index(.items, 0, 0)
    End With
End Sub
the code somewhat works, I changed the Range("E1") to E2.... please modify the code to keep the headers as it is or you can skip the headers part I will pre fill those headers, consider data from A3 and populate in E3 onwards...
 
Upvote 0
What about
VBA Code:
Sub test()
    Dim a, w
    Dim i&
        a = Cells(2, 1).CurrentRegion
    With CreateObject("scripting.dictionary")
        For i = 2 To UBound(a)
            If Not .exists(a(i, 1)) Then
                .Add a(i, 1), Array(a(i, 1), a(i, 2), 1)
            Else
                w = .Item(a(i, 1))
                w(1) = w(1) & "," & a(i, 2): w(2) = w(2) + 1
                .Item(a(i, 1)) = w
            End If
        Next
        Range("E3").Resize(.Count, 3) = Application.Index(.items, 0, 0)
    End With
End Sub
 
Upvote 1
Solution
What about
VBA Code:
Sub test()
    Dim a, w
    Dim i&
        a = Cells(2, 1).CurrentRegion
    With CreateObject("scripting.dictionary")
        For i = 2 To UBound(a)
            If Not .exists(a(i, 1)) Then
                .Add a(i, 1), Array(a(i, 1), a(i, 2), 1)
            Else
                w = .Item(a(i, 1))
                w(1) = w(1) & "," & a(i, 2): w(2) = w(2) + 1
                .Item(a(i, 1)) = w
            End If
        Next
        Range("E3").Resize(.Count, 3) = Application.Index(.items, 0, 0)
    End With
End Sub
works well, thanks.
 
Upvote 0
You are very welcome
Thank you for the feedback
Be happy and safe
 
Upvote 0

Forum statistics

Threads
1,215,331
Messages
6,124,311
Members
449,152
Latest member
PressEscape

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top