|
楼主 |
发表于 2022-12-16 10:08
|
显示全部楼层
你好,做出来的数据不准,多个客户只取了第一个数据,后面的数据没有做轧差,群里有位高手做了个,只能实现一部分功能,可以把您的和这个结合下吗?他做的代码如下:
Sub TEST()
Dim ar, br(), n&, m&, sKey$, iRow&
Dim d: Set d = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
ar = Sheets("银行转账").UsedRange
ReDim br(1 To UBound(ar), 1 To 6)
For i = 2 To UBound(ar)
sKey = Trim(ar(i, 1))
If Not d.Exists(sKey) Then
n = n + 1
br(n, 1) = ar(i, 1): br(n, 2) = ar(i, 2)
br(n, 3) = ar(i, 6): br(n, 4) = ar(i, 7)
br(n, 5) = ar(i, 5): br(n, 6) = Val(ar(i, 8))
d(sKey) = n
Else
m = d(sKey)
br(m, 6) = br(m, 6) + Val(ar(i, 8))
End If
Next i
With Sheets("按金额")
.[a1].Resize(1, 8) = Split("客户编号 客户姓名 员工姓名 关系类型 交易日期 资金存取汇总 日初资产 存取比例")
.[a1].CurrentRegion.Offset(1).Clear
.[a2].Resize(n, 8) = br
.[a1].CurrentRegion.Borders.LineStyle = 1
.Cells.Interior.Pattern = xlNone
iRow = Cells(Rows.Count, "a").End(3).Row
For i = 1 To iRow
If .Cells(i, 4).Value = "存量" Then
.Cells(i, 4).Interior.Color = vbYellow
End If
Next i
.Sort.SortFields.Add Columns("D"), xlSortOnCellColor, 1, xlSortNormal
.Sort.SortFields.Add Columns("F"), xlSortOnValues, 1, xlSortNormal
With .Sort
.SetRange [a1].CurrentRegion
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
Application.ScreenUpdating = True
Set d = Nothing
MsgBox "OK!"
End Sub |
|