本帖最后由 一把小刀闯天下 于 2019-7-7 19:32 编辑
'数量、金额给你合计了一下。大小写这论坛找了一个函数给你套用了一下估计差不多
'行高以输出表格的1-16行行高为基准设置的
'"出入库单能不能跟着更新"没看到条件自己处理一下吧,应该没什么难度的吧,,,
Option Explicit
Sub test()
Dim arr, i, j, k, a, b, m, cnt, p, sum1, sum2
Application.ScreenUpdating = False
Sheets("出入库单").Activate
[a17].Resize(10 ^ 4, 6).Clear
arr = Sheets("出入库明细").[a1].CurrentRegion.Offset(1).Resize(, 8)
Call dsort(arr, 1, UBound(arr, 1) - 1, 1, UBound(arr, 2), 1)
For i = 1 To UBound(arr, 1) - 1
For j = i To UBound(arr, 1) - 1
If arr(j, 1) <> arr(j + 1, 1) Then
Call dsort(arr, i, j, 1, UBound(arr, 2), 2)
p = i
For k = i To j
If arr(k, 1) <> arr(k + 1, 1) Or arr(k, 2) <> arr(k + 1, 2) Then
ReDim brr(1 To 10, 1 To 6)
For a = p To k
m = m + 1
sum1 = sum1 + arr(a, 5)
sum2 = sum2 + arr(a, 7)
For b = 3 To 8
brr(m, b - 2) = arr(a, b)
Next
If m = 10 Then
Rows(1).Resize(16).Copy Rows(cnt + 1)
Cells(cnt + 2, "b") = arr(a, 2)
Cells(cnt + 2, "e") = arr(a, 1)
Cells(cnt + 14, "c") = sum1
Cells(cnt + 14, "e") = sum2
Cells(cnt + 15, "b") = RMBcase(sum2)
Cells(cnt + 4, "a").Resize(10, 6) = brr
cnt = cnt + 16: m = 0: sum1 = 0: sum2 = 0
ReDim brr(1 To 10, 1 To 6)
End If
Next
If m > 0 Then
Rows(1).Resize(16).Copy Rows(cnt + 1)
Cells(cnt + 2, "b") = arr(a - 1, 2)
Cells(cnt + 2, "e") = arr(a - 1, 1)
Cells(cnt + 14, "c") = sum1
Cells(cnt + 14, "e") = sum2
Cells(cnt + 15, "b") = RMBcase(sum2)
Cells(cnt + 4, "a").Resize(10, 6) = brr
cnt = cnt + 16
End If
p = k + 1: m = 0: sum1 = 0: sum2 = 0
End If
Next
i = j: Exit For
End If
Next
Next
Application.ScreenUpdating = True
End Sub
Function dsort(arr, first, last, left, right, key)
Dim i, j, k, t
For i = first To last - 1
For j = i + 1 To last
If arr(i, key) > arr(j, key) Then
For k = left To right
t = arr(i, k): arr(i, k) = arr(j, k): arr(j, k) = t
Next
End If
Next j, i
End Function
Function RMBcase(Num) As String
Dim s As String, i As Long
s = Replace(Replace(Application.Text(Format(Num, "0.00"), "[DBNum2]"), "-", "负"), ".", "元"): i = Len(s)
Select Case InStr(1, s, "元", 1)
Case 0: If s = "零" Then s = "" Else s = s & "元整"
Case i - 1: s = s & "角整"
Case i - 2: s = left(s, i - 1) & "角" & right(s, 1) & "分"
End Select: RMBcase = Replace(Replace(Replace(s, "零元零角", ""), "零元", ""), "零角", "零")
End Function
|