|
楼主 |
发表于 2018-7-26 22:02
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 向東 于 2018-7-27 18:39 编辑
2.0版本来了,绝对原创,分享给大家。
明了的数量汇总显示.rar
(26.21 KB, 下载次数: 14)
- Private Sub CommandButton2_Click() ' 汇总
- Dim r, i, j, h, M As Long
- Dim Rng As Variant
-
- r = Worksheets("汇总表").Range("C65536").End(xlUp).Row
- Rng = Worksheets("汇总表").Range("A1:I" & r).Value
-
- '------------------------------------------------------------------------按 仓位、货品编码 排序
- Application.ScreenUpdating = True
- Range("A2:I" & r).Sort Key1:=Range("D2"), Order1:=xlAscending, Key2:=Range("E2") _
- , Order2:=xlAscending, Key3:=Range("G2"), Order3:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=True _
- , Orientation:=xlTopToBottom, SortMethod:=xlPinYin, DataOption1:= _
- xlSortNormal, DataOption2:=xlSortNormal
- '------------------------------------------------------------------------按 货品名 对 大于1的数量求和
- r = Worksheets("汇总表").Range("C65536").End(xlUp).Row
- Rng = Worksheets("汇总表").Range("A1:I" & r).Value
-
- M = 2
- f: For i = M To r
- If Rng(i - 1, 5) = Rng(i, 5) And Rng(i, 7) >= 1 And Rng(i - 1, 8) = "□" Then '商品编码 与上一行相同, 且 数量大于等于1 ,且 上一行 核对列 为"□" (核对列 除了数量是小数外,全部是"□")
- h = 2
- For j = i + 1 To r '查询有多少相同的行
- If Rng(i, 5) = Rng(j, 5) And Rng(j, 7) >= 1 Then 'rng(j,7) 第7列是数量
- h = h + 1 '累计行数
- End If
- Next
-
- If h = 2 Then '两行相同 的商品编码
- If ((Rng(i - 1, 7) + Rng(i, 7))) < 10 Then
- Range("H" & i - 1) = "╮ "
- Range("H" & i) = "╯" & (Rng(i - 1, 7) + Rng(i, 7)) & " " '1位数字,多加个空格,看起来整齐。
- Else
- Range("H" & i - 1) = "╮ "
- Range("H" & i) = "╯" & (Rng(i - 1, 7) + Rng(i, 7))
- End If
- ElseIf h > 2 Then
- Range("H" & i - 1) = "─╮"
- Range("H" & i & ":H" & i + h - 3) = "│"
- Range("H" & i + Int(h / 2) - 1).Formula = "=SUM(G" & i - 1 & ":G" & i + h - 2 & ")" '汇总数量(奇数行覆盖上一行内容)
- Range("H" & i + h - 2) = "─╯"
- End If
-
- M = i + h
- GoTo f
- End If
- Next
- Range("F2:H" & r).Select '选择 需要打印的 区域
- Application.ScreenUpdating = False
- '------------------------------------------------------------------------打印 汇总
- If MsgBox("要先【打印】此汇总单吗?", vbQuestion + vbYesNo, "打印提示") = vbYes Then
- ActiveSheet.PageSetup.PrintArea = ActiveSheet.Range("F2:H" & r).Address '设置选择区域 为打印区域
- ActiveSheet.PrintOut Copies:=1, Collate:=True
- End If
- End Sub
复制代码
|
|