• 20170523xlVBA多条件分类求和一例


    Public Sub NextSeven_CodeFrame()
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        Application.Calculation = xlCalculationManual
        Application.StatusBar = ">>>>>>>>程序正在运行>>>>>>>>"
    
        On Error GoTo ErrHandler
    
        Dim StartTime, UsedTime As Variant
        StartTime = VBA.Timer
        '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        Dim Wb As Workbook
        Dim Sht As Worksheet
        Dim OpenWb As Workbook
        Dim OneSht As Worksheet
    
        Dim Arr As Variant
        Dim i As Long
    
        Dim FolderPath As String
        Dim FileName As String
        Dim FileCount As Long
    
        Dim OneKey
        Dim Key As String
        Dim Dic As Object
    
    
        Set Dic = CreateObject("Scripting.Dictionary")
    
        '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        Set Wb = Application.ThisWorkbook
        Set Sht = Wb.Worksheets("分类汇总")
    
        FolderPath = Wb.Path & Application.PathSeparator
        FileCount = 0
        FileName = Dir(FolderPath & "*.xls*")
        Do While FileName <> ""
            If FileName <> ThisWorkbook.Name Then
                FileCount = FileCount + 1
                Set OpenWb = Application.Workbooks.Open(FolderPath & FileName)
                With OpenWb
                    For Each OneSht In .Worksheets
                        If OneSht.Name Like "*月" Then
                            With OneSht
                                endrow = .Cells(.Cells.Rows.Count, "B").End(xlUp).Row
                                Set Rng = .Range("A3:F" & endrow)
                                Arr = Rng.Value
                                For i = LBound(Arr) To UBound(Arr)
                                    Key = .Name & ";" & CStr(Arr(i, 2) & ";" & Arr(i, 3))
                                    Dic(Key) = Dic(Key) + Arr(i, 4)
                                Next i
                            End With
                        End If
                    Next OneSht
                    .Close False
                End With
            End If
            FileName = Dir
        Loop
    
    
        With Sht
            .Cells.Clear
            .Range("A1:D1").Value = Array("月份", "型号与品名", "工序", "总数")
            i = 1
            For Each OneKey In Dic.Keys
                i = i + 1
                Key = CStr(OneKey)
                .Cells(i, 1).Value = Split(Key, ";")(0)
                .Cells(i, 2).Value = Split(Key, ";")(1)
                .Cells(i, 3).Value = Split(Key, ";")(2)
                .Cells(i, 4).Value = Dic(OneKey)
            Next OneKey
            SetEdges .UsedRange
        End With
    
    
        '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        UsedTime = VBA.Timer - StartTime
        MsgBox "本次耗时:" & Format(UsedTime, "0.000秒"), vbOKOnly, "Tips"
    
    ErrorExit:
        Set Wb = Nothing
        Set Sht = Nothing
        Set OpenWb = Nothing
        Set OneSht = Nothing
        Set Rng = Nothing
    
    
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True
        Application.Calculation = xlCalculationAutomatic
        Application.StatusBar = False
        Exit Sub
        '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    ErrHandler:
        If Err.Number <> 0 Then
            MsgBox Err.Description & "!", vbCritical, "Tips"
            'Debug.Print Err.Description
            Err.Clear
            Resume ErrorExit
        End If
    End Sub
    

      

  • 相关阅读:
    哥们儿太猛了
    word文档中出现一串乱码数字
    outlook添加附件时报错--“附件大小超过了允许的范围”
    windows常用脚本备忘
    vim常用命令
    win10中使用scp命令传输文件
    win10安装域控管理工具组件
    edge浏览器离线下载
    SQL_从星期一到星期六自动打卡SQL代码
    用友U8按BOM计算销售订单物料需求SQL代码 第一稿
  • 原文地址:https://www.cnblogs.com/nextseven/p/7128235.html
Copyright © 2020-2023  润新知