【发布时间】:2016-07-21 03:30:02
【问题描述】:
我有 18000 行和 26 列。
样本数据:
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
我必须根据列(B、F、G)查找重复的行。如果这三列的行相同,则将E列的单元格的值相加为一行,并删除重复的行以仅保留其中一行。
结果:
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
我浏览了一些网站和博客,想出了下面发布的代码。
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
【问题讨论】: