|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
用字典有两个数据有问题。
第一个是西瓜,在7月27日,有两条数据
第二个是老盐菜 在7月19日,有两条数据
代码如下:
- Sub test()
- Dim arr, brr, i%, j%
- Dim dic As Object, str As String, m As Double, n As Double
- Dim RqDay%
- Set dic = CreateObject("scripting.dictionary")
- With Sheets("系统表2")
- arr = .Range("a1").CurrentRegion
- For i = 2 To UBound(arr)
- If arr(i, 16) = "客用费用" Then
- RqDay = Day(arr(i, 3)): str = arr(i, 6)
- If arr(i, 9) <> "" Then
- If Not dic.exists(RqDay & str) Then
- dic(RqDay & str) = Array(arr(i, 9), arr(i, 10), arr(i, 11))
- End If
- Else
- If Not dic.exists(RqDay & str) Then
- dic(RqDay & str) = Array(arr(i, 12), arr(i, 13), arr(i, 14))
- End If
- End If
- End If
- Next i
- End With
- With Sheets("易耗品明细表")
- brr = .Range("a1").CurrentRegion
- 'm = 0: n = 0
- For i = 3 To UBound(brr, 2) - 4 Step 3
- For j = 4 To UBound(brr)
- If Len(brr(2, i)) = 2 Then
- kk = Left(brr(2, i), 1) & brr(j, 1)
- Else
- kk = Left(brr(2, i), 2) & brr(j, 1)
- End If
- If dic.exists(kk) Then
- brr(j, i) = dic(kk)(0)
- brr(j, i + 1) = dic(kk)(1)
- brr(j, i + 2) = dic(kk)(2)
- End If
- Next j
- Next i
- For i = 4 To UBound(brr)
- For j = 3 To UBound(brr, 2) - 4 Step 3
- brr(i, UBound(brr, 2) - 1) = brr(i, UBound(brr, 2) - 1) + brr(i, j)
- brr(i, UBound(brr, 2)) = brr(i, UBound(brr, 2)) + brr(i, j + 2)
- Next j
- Next i
- .Range("a1").Resize(UBound(brr), UBound(brr, 2)) = ""
- .Range("a1").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
|