序号 | 父单 | 金额 | 父单金额 |
1 | sid1 | 100 | 1050 |
2 | sid1 | 200 | |
3 | sid1 | 300 | |
4 | sid1 | 450 | |
5 | sid2 | 45 | 1231 |
6 | sid2 | 165 | |
7 | sid2 | 998 | |
8 | sid2 | 23 | |
9 | sid3 | 13 | 106 |
10 | sid3 | 93 | |
11 | sid4 | 45 | 45 |
12 | sid5 | 45 | 45 |
实现效果求相同父单总金额
步骤一、父单排序
步骤二、
打开VBA编辑器(Alt + F11),将上述代码复制粘贴到新建的模块中。然后,按下F5键运行。
Sub MergeCellsInColumnDWithCondition()
Dim lastRow As Long
Dim i As Long
lastRow = Cells(Rows.Count, "D").End(xlUp).Row
For i = lastRow To 2 Step -1
If Cells(i, "D").Value = Cells(i - 1, "D").Value And Cells(i, "B").Value = Cells(i - 1, "B").Value Then
Range("D" & i).Value = ""
Range("D" & i - 1 & ":D" & i).MergeCells = True
End If
Next i
End Sub