Vba Macro for remove duplicate values and sum other column

Ghoghnuse

New Member
Joined
May 4, 2017
Messages
12
Hi

I have a table like this :

A
B
C
D
E
F
G
16
CODE
AMOUNT
17
202
100
18
203
200
19
202
200
20
205
300
21
203
500
22
208
150
23
203
100
24
205
500

<tbody>
</tbody>

















I Want a macro to remove Duplicate Codes and calculate sum of each codes and copy results to new sheet .

Like This :

Code
Sum of Amounts
202
300
203
800
205
800
208
150

<tbody>
</tbody>









I know that i could use Pivot Table but i want to use macro .

Thanks in Advance .
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
How about
Code:
Sub RemoveDupe_sum()


    Dim Cl As Range
    Dim Cnt As Long
    
    With CreateObject("scripting.dictionary")
        For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
            If Not .exists(Cl.Value) Then
                .Add Cl.Value, Cl.Offset(, 6).Value
            Else
                .Item(Cl.Value) = .Item(Cl.Value) + Cl.Offset(, 6).Value
            End If
        Next Cl
        Sheets("Sheet1").Range("A1").Resize(.Count).Value = Application.Transpose(.Keys)
        Sheets("Sheet1").Range("B1").Resize(.Count).Value = Application.Transpose(.items)
        End With

End Sub
 
Upvote 0
Thanks a lot Fluff ! Work like a charm ...

But how could i copy result to first blank cell end of column A in sheet1 ?
 
Last edited:
Upvote 0
Use
Code:
Sub RemoveDupe_sum()


    Dim Cl As Range
    Dim Cnt As Long
    
    With CreateObject("scripting.dictionary")
        For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
            If Not .exists(Cl.Value) Then
                .Add Cl.Value, Cl.Offset(, 6).Value
            Else
                .Item(Cl.Value) = .Item(Cl.Value) + Cl.Offset(, 6).Value
            End If
        Next Cl
        
        Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(.Count).Value = Application.Transpose(.Keys)
        Sheets("Sheet1").Range("B" & Rows.Count).End(xlUp).Offset(1).Resize(.Count).Value = Application.Transpose(.items)
        End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

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