|
楼主 |
发表于 2024-7-1 14:59
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
9楼的结果是错误的
Sub text2()
Dim arr, d As Object
Set d = VBA.CreateObject("scripting.dictionary")
arr = Range("a1").CurrentRegion
For i = UBound(arr) To 4 Step -1
If arr(i, 4) = "总计" Then d(arr(i, 4)) = d(arr(i, 4)) & " " & i
Next
s = Split(d("总计"), " ")
For r = 1 To UBound(s)
If r = UBound(s) Then
fr = 4
Else
fr = s(r + 1)
End If
er = s(r)
d.RemoveAll
Set unrng = Rows(5000)
For i = fr To er
If Cells(i, 4).Value = "" Then Exit For
If Cells(i, 5).Value <> "" Then
If Not d.exists(Cells(i, 5).Value) Then
d(Cells(i, 5).Value) = i
Else
y = d(Cells(i, 5).Value)
Cells(y, 7).Value = Cells(y, 7).Value + Cells(i, 7).Value
Cells(y, 9).Value = Cells(y, 9).Value + Cells(i, 9).Value
Set unrng = Union(unrng, Rows(i))
End If
End If
Next
unrng.EntireRow.Delete
Next
Set d = Nothing
End Sub
|
|