|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub a2()
- Dim sj(1 To 7, 1 To 3)
- r = -7: c = 7
- With Sheets("明细")
- arr = .Range("h02:n" & .Range("j50").End(xlUp).Row)
- wb = .Cells(1, 13) & ":"
- For i = 1 To 7
- sj(i, 1) = .Cells(1, i + 7)
- Next i
- End With
- Dim d: Set d = CreateObject("scripting.dictionary")
- Dim drow: Set drow = CreateObject("scripting.dictionary")
- For i = 1 To UBound(arr)
- sKey = arr(i, 3)
- If d.exists(sKey) Then
- d(sKey) = d(sKey) + arr(i, 6)
- Else
- d(sKey) = arr(i, 6)
- drow(sKey) = i
- End If
- Next
- iCnt = 0
- For Each sKey In d.Keys
- i = drow(sKey)
- iCnt = iCnt + 1
- If iCnt Mod 3 = 1 Then
- r = r + 8
- Cells(r, 1).Resize(7, 8).Borders.LineStyle = xlContinuous
- Cells(r, 1).Resize(7, 8).HorizontalAlignment = xlCenter
- Cells(r + 5, 1).Resize(1, 8).NumberFormatLocal = "#,##0.00_ "
- Cells(r + 6, 1).Resize(1, 8).NumberFormatLocal = "#,##0.0000"
- End If
- c = c + 3
- If c > 7 Then
- c = 1
- End If
- For j = 1 To 7
- sj(j, 2) = arr(i, j)
- If j = 6 Then sj(j, 2) = d(sKey)
- Next j
- If sj(7, 2) < 10 Then
- sj(6, 1) = wb & "JPY"
- Else
- sj(6, 1) = wb & "USD"
- End If
- Cells(r, c).Resize(7, 2) = sj
- Next
- End Sub
复制代码 |
|