VBA Code to delete duplicate values from a row and sum the corresponding column values in another sheet

Jyotirmaya

Board Regular
Joined
Dec 2, 2015
Messages
216
Office Version
  1. 2019
Platform
  1. Windows
I have excel sheet in Sheet1 in Column ABC, I have data, there are more than 5000 rows. I want that in Sheet2 ABC Column the duplicates from column A is to be deleted, & B,C Columns value to be added. Only unique values to be there only in the Column A after deleting the duplicates. Please help me for the code.

Screenshot 2025-01-05 160622.png
 
& B,C Columns value to be added
Added to Sheet 2 ?

Those values added to columns B&C of Sheet 2 or to columns A&B of Sheet 2 ?
 
Upvote 0
Try:
VBA Code:
Sub DeleteDups()
    Application.ScreenUpdating = False
    Dim v As Variant, i As Long, dic As Object, srcWS As Worksheet, desWS As Worksheet, lRow As Long, fnd As Range
    Set srcWS = Sheets("Sheet1")
    Set desWS = Sheets("Sheet2")
    Set dic = CreateObject("Scripting.Dictionary")
    With srcWS
        lRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        v = .Range("A2:A" & lRow).Resize(, 3).Value
        For i = LBound(v) To UBound(v)
            If Not dic.exists(v(i, 1)) Then
                dic.Add v(i, 1), Nothing
                desWS.Cells(desWS.Rows.Count, 1).End(xlUp).Offset(1).Resize(, 3).Value = Array(v(i, 1), desWS.Range("B" & i + 1) + v(i, 2), desWS.Range("C" & i + 1) + v(i, 3))
            Else
                Set fnd = desWS.Range("A:A").Find(v(i, 1))
                desWS.Range("A" & fnd.Row).Resize(, 3).Value = Array(v(i, 1), desWS.Range("B" & fnd.Row) + v(i, 2), desWS.Range("C" & fnd.Row) + v(i, 3))
            End If
        Next i
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try:
VBA Code:
Sub DeleteDups()
    Application.ScreenUpdating = False
    Dim v As Variant, i As Long, dic As Object, srcWS As Worksheet, desWS As Worksheet, lRow As Long, fnd As Range
    Set srcWS = Sheets("Sheet1")
    Set desWS = Sheets("Sheet2")
    Set dic = CreateObject("Scripting.Dictionary")
    With srcWS
        lRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        v = .Range("A2:A" & lRow).Resize(, 3).Value
        For i = LBound(v) To UBound(v)
            If Not dic.exists(v(i, 1)) Then
                dic.Add v(i, 1), Nothing
                desWS.Cells(desWS.Rows.Count, 1).End(xlUp).Offset(1).Resize(, 3).Value = Array(v(i, 1), desWS.Range("B" & i + 1) + v(i, 2), desWS.Range("C" & i + 1) + v(i, 3))
            Else
                Set fnd = desWS.Range("A:A").Find(v(i, 1))
                desWS.Range("A" & fnd.Row).Resize(, 3).Value = Array(v(i, 1), desWS.Range("B" & fnd.Row) + v(i, 2), desWS.Range("C" & fnd.Row) + v(i, 3))
            End If
        Next i
    End With
    Application.ScreenUpdating = True
End Sub
THANK YOU SO MUCH
 
Upvote 0

Forum statistics

Threads
1,226,835
Messages
6,193,241
Members
453,783
Latest member
Chandni

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