20170814xlVBA限定日期按客户分类汇总

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了20170814xlVBA限定日期按客户分类汇总相关的知识,希望对你有一定的参考价值。

原始数据表:

技术分享

汇总格式:

技术分享

 

 

Sub subtotalDic()
    Dim Wb As Workbook
    Dim Sht As Worksheet
    Dim oSht As Worksheet
    Dim mYear As String
    Dim mMon As String
    Dim Arr As Variant
    Dim i As Long, j As Long
    
    Dim Dic As Object
    Set Dic = CreateObject("Scripting.Dictionary")
    Set Wb = Application.ThisWorkbook
    Set Sht = Wb.Worksheets("销售台账")
    Set oSht = Wb.Worksheets("每月汇总")
    
    With oSht
        mYear = .Range("A2").Text
        mMon = .Range("C2").Text
    End With
    
    With Sht
        endrow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row
        If endrow <= 3 Then Exit Sub
        Set Rng = .Range("A4:N" & endrow)
        Arr = Rng.Value
        For i = LBound(Arr) To UBound(Arr)
            If CStr(Arr(i, 1)) = mYear And CStr(Arr(i, 2)) = mMon Then
                Key = CStr(Arr(i, 4))
                Dic(Key) = Dic(Key) + Arr(i, 8)
            End If
        Next i
    End With
    
    With oSht
        endrow = .Cells(.Cells.Rows.Count, 2).End(xlUp).Row
        For i = 5 To endrow
            Key = .Cells(i, 2).Text
            .Cells(i, 3).Value = Dic(Key)
        Next i
        
        endrow = .Cells(.Cells.Rows.Count, 5).End(xlUp).Row
        For i = 5 To endrow
            Key = .Cells(i, 5).Text
            .Cells(i, 6).Value = Dic(Key)
        Next i
    End With
    
    
    Set Wb = Nothing
    Set Sht = Nothing
    Set oSht = Nothing
    Set Rng = Nothing
    Set Dic = Nothing
    
End Sub

  

以上是关于20170814xlVBA限定日期按客户分类汇总的主要内容,如果未能解决你的问题,请参考以下文章

sql数据按月统计 每天的数据汇总成一条数据按月显示

20170617xlVBA销售数据分类汇总

20170711xlVBA自定义分类汇总一例

20170624xlVBA正则分割分类汇总

20170928xlVBA自定义分类汇总

20170324xlVBA最简单分类计数