|
参与一下。。。
- Sub ykcbf() '//2024.8.22
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- ReDim zrr(1 To 1000)
- Set sh = ThisWorkbook.Sheets("下单数据")
- sh.UsedRange.Offset(1).Clear
- sh.UsedRange.UnMerge
- With Sheets("数据源")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .[a1].Resize(r, 14)
- For i = 2 To UBound(arr)
- If arr(i, 2) <> arr(i - 1, 2) Then M = M + 1: zrr(M) = Array(i, i)
- If i = r Then zrr(M)(1) = r
- If i < r Then
- If arr(i, 2) = arr(i - 1, 2) And arr(i, 2) <> arr(i + 1, 2) Then zrr(M)(1) = i
- End If
- Next
- For x = 1 To M
- r1 = zrr(x)(0): r2 = zrr(x)(1)
- n = r2 - r1 + 1
- Set Rng = .Cells(r1, 1).Resize(n, 14)
- If x = 1 Then
- Rng.Copy sh.[b2]
- Else
- r = sh.Cells(Rows.Count, 3).End(3).Row
- Rng.Copy sh.Cells(r + 2, 2)
- End If
- sh.Cells(r2 + x, 1).Resize(, 15).Interior.ColorIndex = 6
- sh.Cells(r2 + x, 2) = "小计"
- For j = 13 To 15
- sh.Cells(r2 + x, j) = Application.Sum(sh.Cells(r1 + x - 1, j).Resize(n))
- Next
- Next
- End With
- With sh
- r = .Cells(Rows.Count, 2).End(3).Row
- .Cells(r + 2, 2) = "合计数量"
- With .[a1].Resize(r + 2, 15)
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- For j = 8 To 10
- .Cells(r + 2, j) = Application.Sum(sh.Cells(2, j).Resize(r))
- Next
- .Cells(r + 2, 13) = Application.Sum(sh.Cells(r + 2, 8).Resize(, 3))
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|