Checking Duplicate values and delete rows
Hello, everyone
I have a spreadsheet, like below, I want to check for duplicate values in columnA and then sum the relevant values in colB, eg: row 3 to 5 is the same, so sum(b3:b5), then delete the irrelevant rows leaving the total in column B
Any help will be appreciated.
Existing columns;
col A col B
1 A0202231 -4.73
2 A0202232 135.09
3 A0202238 89.54
4 A0202238 -90.72
5 A0202238 -0.18
6 A0202243 -0.36
7 A0202282 22.6
8 A0202311 -0.12
Expected result as follows:
col A col B
1 A0202231 -4.73
2 A0202232 135.09
3 A0202238 -1.36
4 A0202243 -0.36
5 A0202282 22.6
6 A0202311 -0.12
I have been using the following code in an attempt to achieve the result:
Private Sub cmdCheck_Click()
Dim X
Set X = Worksheets("Sheet1").Range("F1")
Set currentCell = Worksheets("Sheet1").Range("E1")
Do While Not IsEmpty(currentCell)
Set nextCell = currentCell.Offset(1, 0)
If nextCell.Value = currentCell.Value Then
X = X + 1
currentCell.EntireRow.Delete
End If
Set currentCell = nextCell
Loop
End sub
This does delete the duplicate rows but does not add the values together.
Many thanks
Peter
|