zoukankan      html  css  js  c++  java
  • x01.Excel: 合计件数

    由于 VBA 与 Excel 是耦合的,所以还是先看表:

                      

    件数的计算,用 Mod 即可。但考虑到要求码洋、数量等多种需求,就该 VBA 登场了。代码如下:

    '================================================================
    ' Count (c) 2014 by x01
    '-------------------------
    '   计算每行的整件数和码洋
    '
    ' 参数:
    '   sheet: 所选的表。
    '   numPerBag: 每件的数量。
    '   startRow: 开始的行数。
    '   endRow: 结束的行数。
    '================================================================
    Public Sub Count(sheet, numPerBag, startRow, endRow)
        For i = startRow To endRow
            If Application.WorksheetFunction.IsNumber(sheet.Cells(i, 4)) Then
            If Trim(sheet.Cells(i, 1)) <> "合计" Then
            '通过定价选择行数
            'If 15# = sheet.Cells(i, 3) Then
                '计算每行整包
                sheet.Cells(i, 6) = CStr(Int(sheet.Cells(i, 4) / numPerBag)) & "件+" & CStr(sheet.Cells(i, 4) Mod numPerBag)
                
                '计算每行码洋
                sheet.Cells(i, 5) = sheet.Cells(i, 3) * sheet.Cells(i, 4)
            'End If
            End If
            End If
        Next
        Debug.Print CStr(startRow) & " - " & CStr(endRow)
    End Sub
    
    '=================================================================
    ' SumCol (c) 2014 by x01
    '-----------------------
    '   计算列的合计数,如数量合计,码洋合计等。
    '
    ' 参数:
    '   sheet: 所选的表。
    '   col: 指定的列。
    '   startRow: 开始的行数。
    '   endRow: 结束的行数。
    '=================================================================
    Public Sub SumCol(sheet, col, startRow, endRow)
        Dim result As Double
        result = 0
        For i = startRow To endRow
            If Application.WorksheetFunction.IsNumber(sheet.Cells(i, col)) Then
            If Trim(sheet.Cells(i, 1)) <> "合计" Then
            If 23# = sheet.Cells(i, 3) Then
                result = result + sheet.Cells(i, col)
            End If
            End If
            End If
        Next
        
        Debug.Print CStr(result)
    End Sub

    在表中,如果有多个发货清单,该宏具有很好的穿透能力,使用起来还是挺方便的。使用方法如下:

    1. 仿照 Excel 表的 列 新建一 Excel 表。

    2. 按 Atl + F11 快捷键,在显示窗口中插入模块,将上面代码复制到模块中。

    3. 在命令窗口中输入类似如下命令并回车即可:

         Count Sheet1,30,1,200

  • 相关阅读:
    (6)sql/puls
    (5)Toad for oracle使用
    (4)oracle连接工具和配置监听
    (3)oracle建用户、建表、权限、命名空间
    (2)oracle服务、建库
    (1)oracle安装、卸载、启动、关闭、登陆以及同时遇到的问题
    (1)C#工具箱-公共控件1
    Tarjan
    最小表示法
    STL
  • 原文地址:https://www.cnblogs.com/china_x01/p/3885506.html
Copyright © 2011-2022 走看看