|
- Sub cx()
- arr = Sheet4.Range("A1:I" & Sheet4.Cells(Rows.Count, "A").End(xlUp).Row)
- arr2 = Sheet4.Range("k1:t" & Sheet4.Cells(Rows.Count, "k").End(xlUp).Row)
- Dim dic As Object
- Set dic = CreateObject("scripting.dictionary")
- For i = 3 To UBound(arr)
- If InStr(arr(i, 1), ".") > 0 Then
- rq = CStr(Day(CDate(Replace(arr(i, 1), ".", "-"))))
- Else
- rq = CStr(Day(arr(i, 1)))
- End If
- Key = UCase(arr(i, 3)) & "," & UCase(arr(i, 5))
- If Not dic.exists(Key) Then
- Set dic(Key) = CreateObject("scripting.dictionary")
- End If
- dic(Key)(rq) = dic(Key)(rq) + arr(i, 6)
- Next
- For i = 3 To UBound(arr2)
- If InStr(arr2(i, 1), ".") > 0 Then
- rq = CStr(Day(CDate(Replace(arr2(i, 1), ".", "-"))))
- Else
- rq = CStr(Day(arr2(i, 1)))
- End If
- Key = UCase(arr2(i, 2)) & "," & UCase(arr2(i, 9))
- If Not dic.exists(Key) Then
- Set dic(Key) = CreateObject("scripting.dictionary")
- End If
- dic(Key)(rq) = dic(Key)(rq) + arr2(i, 3)
- Next
- Keys = dic.Keys
- items = dic.items
- ReDim my(1 To dic.Count, 1 To 2)
- For i = 0 To UBound(Keys)
- s = Keys(i)
- k = k + 1
- my(k, 1) = Split(s, ",")(0)
- my(k, 2) = Split(s, ",")(1)
- Next
- Sheet1.Range("B3").Resize(k, 2).ClearContents
- Sheet1.Range("B3").Resize(k, 2) = my
- Sheet1.Range("M3").Resize(k, 1).ClearContents
- Sheet1.[m3].Resize(UBound(my), 1) = Application.Index(my, 0, 2)
- dr = Sheet1.Range("N1:AR" & Sheet1.Cells(Rows.Count, "B").End(xlUp).Row)
- ReDim brr(1 To UBound(my), 1 To 31)
- k = 0
- For i = 1 To UBound(my)
- If my(i, 1) <> "" Then
- k = k + 1
- s = my(i, 1) & "," & my(i, 2)
- For j = 1 To UBound(dr, 2)
- ss = CStr(dr(2, j))
- If dic.exists(s) Then
- brr(k, j) = dic(s)(ss)
- End If
- Next
- End If
- Next
- Sheet1.Range("n3:AR" & Rows.Count).ClearContents
- Sheet1.Range("N3").Resize(k, 31) = brr
- End Sub
复制代码
|
|