|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 一键合并汇总()
Dim arr, k%, d
Dim br()
Set d = CreateObject("scripting.dictionary")
arr = Sheet1.Range("a1").CurrentRegion
ReDim br(1 To UBound(arr), 1 To 6)
m = 1
For j = 1 To UBound(arr, 2)
br(m, j) = arr(1, j)
Next j
br(m, 6) = "余额"
For k = 2 To UBound(arr)
If arr(k, 1) <> "" Then
t = d(arr(k, 1))
If t = "" Then
m = m + 1
d(arr(k, 1)) = m
t = m
br(m, 1) = arr(k, 1)
br(m, 4) = arr(k, 4)
End If
If br(t, 2) = "" Then
br(t, 2) = arr(k, 2)
Else
br(t, 2) = br(t, 2) & "," & arr(k, 2)
End If
br(t, 3) = br(t, 3) + arr(k, 3)
br(t, 5) = br(t, 5) + arr(k, 5)
br(t, 6) = br(t, 5) - br(t, 3)
End If
Next k
With Sheets("Sheet3")
.Select
.Range("a:L") = ""
.Range("a1").Resize(m, 6) = br
End With
End Sub
|
|