I have 18000 rows and 26 columns.
Sample data:
A(Name) B(Mat_Num) C(Items) D(group) E(Summon) F(Plant) G(Batch_num)
1.Ram 1235 HA1 Micro 545.5 1327 893A1
2.ram 12354 rt2 Senf 5678 0001 1063F
3.Joseph 12354 cf1 Macro 9844 0001 1063F
4.andreas 12354 dw1 HR 6633.95 0001 1063F
5.John 1235 ff1 Finance 22555.09 1327 893A1
6.Russel 987 ad1 Sales 6423 0001 jjg67
7.Holger 00 dd1 purchase 3333 1327 dd567
8.Gottfried 234 fa1 rot 663 345 45678
I have to find duplicate rows based on columns (B, F, G). If the rows of these three columns are the same then sum the value of cells of column E to one row and delete duplicate rows to keep only one of the rows.
Result:
A(Name) B(Mat_Num) C(Items) D(group) E(Summon) F(Plant) G(Batch_num)
1.Ram 1235 HA1 Micro 23101 1327 893A1
2.ram 12354 rt2 Senf 22155.95 0001 1063F
I have gone through some websites and blogs to come up with code posted below.
Sub Sample()
Dim LastRowcheck As Long, n1 As Long
Dim DelRange As Range
With Worksheets("Sheet1")
LastRowcheck = .Range("A" & .Rows.Count).End(xlUp).Row
For n1 = 1 To LastRowcheck
If .Cells(n1, 1).Value = Cells(n1 + 1, 1).Value Then
If DelRange Is Nothing Then
Set DelRange = .Rows(n1)
Else
Set DelRange = Union(DelRange, .Rows(n1))
End If
End If
Next n1
If Not DelRange Is Nothing Then DelRange.Delete
End With
End Sub