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限定日期按客户分类汇总的主要内容,如果未能解决你的问题,请参考以下文章