Sub 日期別()
On Error Resume Next
lastrow = Sheets("運營日報").Range("a1048576").End(xlUp).Row
lastday = VBA.Day(Sheets("運營日報").Range("a" & lastrow)) + 1
lastcolumn = Sheets("運營統計表").Range("ag3").End(xlToLeft).Column + 1
For daterow = lastcolumn To lastday
With Sheets("運營統計表")
Set d = CreateObject("scripting.dictionary")
Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
Set d3 = CreateObject("scripting.dictionary")
Set d4 = CreateObject("scripting.dictionary")
arr = Sheets("運營日報").Range("a1:y" & lastrow)
For a = 4 To UBound(arr)
If VBA.Day(arr(a, 1)) = .Cells(2, daterow) Then
If Not d.exists(arr(a, 3)) Then '訂單號的去重計數
d.Add arr(a, 3), ""
End If
If Not d1.exists(arr(a, 4)) Then '商戶的去重計數
d1.Add arr(a, 4), ""
End If
If Not d2.exists(arr(a, 5)) Then 'B端門店數的去重計數
d2.Add arr(a, 5), ""
End If
If Sheets("運營日報").Range("o" & a) = "收空瓶" Then
If Not d3.exists(arr(a, 5)) Then '特殊門店去重計數
d3.Add arr(a, 5), ""
End If
d4(arr(a, 1)) = d4(arr(a, 1)) + arr(a, 8) '特殊業務件數的匯總求和
End If
End If
Next
cou = d.Count
cou1 = d1.Count
cou2 = d2.Count
cou3 = d3.Count
cou4 = d4.items
.Cells(3, daterow) = cou
.Cells(4, daterow) = cou1
.Cells(5, daterow) = cou2
.Cells(9, daterow) = cou3
.Cells(11, daterow) = cou4
d.RemoveAll
d1.RemoveAll
d2.RemoveAll
d3.RemoveAll
d4.RemoveAll
'--------------
With Sheets("運營日報")
dat = DateSerial(2018, VBA.Month(Sheets("運營日報").Range("a" & lastrow)), daterow - 1)
'vba.year,month,day,這些屬性雖然要求填寫date類型的值,但是填入文本型也是可以的。
'dateserial 屬性可以是integer,這個長整型,可以是時間格式,可以是文本格式的數字,可以是數字格式的。
Sheets("運營統計表").Cells(6, daterow) = WorksheetFunction.SumIfs(.Range("h4:h" & lastrow), .Range("a4:a" & lastrow), _
dat)
Sheets("運營統計表").Cells(7, daterow) = WorksheetFunction.SumIfs(.Range("i4:i" & lastrow), .Range("a4:a" & lastrow), _
dat) / 1000
Sheets("運營統計表").Cells(8, daterow) = WorksheetFunction.SumIfs(.Range("j4:j" & lastrow), .Range("a4:a" & lastrow), _
dat)
Sheets("運營統計表").Cells(10, daterow) = Sheets("運營統計表").Cells(9, daterow) / Sheets("運營統計表").Cells(5, daterow)
Sheets("運營統計表").Cells(12, daterow) = Sheets("運營統計表").Cells(11, daterow) / Sheets("運營統計表").Cells(6, daterow)
Sheets("運營統計表").Cells(13, daterow) = WorksheetFunction.CountIfs(.Range("v4:v" & lastrow), "*異常", .Range("a4:a" & lastrow), _
dat)
Sheets("運營統計表").Cells(14, daterow) = Sheets("運營統計表").Cells(13, daterow) / Sheets("運營統計表").Cells(3, daterow)
Sheets("運營統計表").Cells(15, daterow) = WorksheetFunction.CountIfs(.Range("v4:v" & lastrow), "<>*訂單超時異常*", .Range("a4:a" & lastrow), _
dat)
Sheets("運營統計表").Cells(16, daterow) = Sheets("運營統計表").Cells(15, daterow) / Sheets("運營統計表").Cells(3, daterow)
End With
'-------------
End With
Next
End Sub