Sub tt() Dim arr, arr1, arr2 Dim i As Long, j As Integer Dim temp1 As Double, temp2 As Long With Sheet1 arr = .Range(.Cells(2, 1), .Cells(65536, 3).End(xlUp)) End With With Sheet2 arr1 = .Range(.Cells(7, 2), .Cells(65536, 2).End(xlUp)) End With ReDim arr2(1 To UBound(arr1, 1), 1 To 2) For j = 1 To UBound(arr1, 1) For i = 1 To UBound(arr, 1) If CDate(arr(i, 3)) < CDate("2010-2-1") And arr(i, 1) = arr(j, 1) Then temp1 = temp1 + arr(i, 2) If arr(i, 2) > 500 Then temp2 = temp2 + 1 End If Next arr2(j, 1) = temp1 arr2(j, 2) = temp2 temp1 = 0 temp2 = 0 Next Sheet2.Range("B7").Offset(0, 1).Resize(UBound(arr2, 1), 2) = arr2 Erase arr, arr1, arr2 End Sub |