|
Sub tt() 'by sdong7 20141031
Dim mxr1, mxr2 As Long
Dim arr1, arr2, dic, arr3(1 To 1000000, 1 To 2)
mxr1 = Sheets("sheet1").[a1048576].End(xlUp).Row
arr1 = Sheets("sheet1").Range("a1:aa" & mxr1)
Set dic = CreateObject("scripting.dictionary")
Workbooks.Open (ThisWorkbook.Path & "\次品返修品统计报表.xls")
Dim sht As Worksheet
For Each sht In Worksheets
mxr2 = Sheets(sht.Name).[a65536].End(xlUp).Row
arr2 = Sheets(sht.Name).Range("a1:c" & mxr2)
For i = 2 To mxr2
If dic.exists("2014." & sht.Name & arr2(i, 1) & arr2(i, 2)) Then
hang = dic("2014." & sht.Name & arr2(i, 1) & arr2(i, 2))
arr3(hang, 2) = arr3(hang, 2) + arr2(i, 3)
Else
k = k + 1
dic("2014." & sht.Name & arr2(i, 1) & arr2(i, 2)) = k
arr3(k, 1) = "2014." & sht.Name & arr2(i, 1) & arr2(i, 2)
arr3(k, 2) = arr2(i, 3)
End If
Next i
Erase arr2
Next
Workbooks("次品返修品统计报表.xls").Close
For i = 3 To mxr1
For j = 3 To 27
If dic.exists(arr1(i, 2) & arr1(i, 1) & arr1(2, j)) Then
m = dic(arr1(i, 2) & arr1(i, 1) & arr1(2, j))
arr1(i, j) = arr1(i, j) + arr3(m, 2)
End If
Next j
Next i
Sheets("sheet1").Range("a1:aa" & mxr1) = arr1
End Sub
|
|