|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 Justin-2016 于 2024-7-3 11:55 编辑
代码问题诊断.zip
(12.31 KB, 下载次数: 2)
Sub test()
Dim arr, x%
Dim dic
Set dic = CreateObject("scripting.dictionary")
With Sheet1
arr = .[A1].CurrentRegion
For x = 2 To UBound(arr)
If Not dic.exists(arr(x, 2)) Then
dic(arr(x, 2)) = arr(x, 4) - arr(x, 5)
arr(x, 6) = dic(arr(x, 2))
Else
dic(arr(x, 2)) = dic(arr(x, 2)) - arr(x, 5)
arr(x, 6) = dic(arr(x, 2))
End If
Next
.[A1].Resize(UBound(arr), 6) = arr
End With
End Sub
|
|