Option Explicit
Sub test()
Dim arr, pos, brr, i, j, k, a, b, n, crr, sum
With Sheets("报价编码")
arr = .Range("a2:j" & .Cells(Rows.Count, "a").End(xlUp).Row + 1)
End With
brr = Sheets("汇总式").[a2:c2]
ReDim crr(1 To UBound(arr, 1), 1 To UBound(arr, 2)) As String
For i = 1 To UBound(arr, 1) - 1
For j = i To UBound(arr, 1) - 1
If arr(j, 3) = brr(1, 1) Then pos = j: Exit For
Next
If j = UBound(arr, 1) Then Exit For
For j = pos To UBound(arr, 1) - 1
If arr(j, 3) <> arr(j + 1, 3) Then
For k = pos To j
If arr(k, 5) = brr(1, 2) Then
For a = k + 1 To j
If Len(arr(a, 2)) - Len(arr(k, 2)) <= brr(1, 3) Then
n = n + 1: sum = sum + arr(a, UBound(arr, 2))
For b = 2 To UBound(arr, 2): crr(n, b - 1) = arr(a, b): Next
End If
If Len(arr(a + 1, 2)) <= Len(arr(k + 1, 2)) Then Exit For
Next
k = j: Exit For
End If
Next
i = j: Exit For
End If
Next j, i
crr(n + 1, UBound(crr, 2) - 2) = "合计"
crr(n + 1, UBound(crr, 2) - 1) = sum
With Sheets("下阶成本").[a2]
.Resize(Rows.Count - 1, UBound(crr, 2)).ClearContents
.Resize(n + 1, UBound(crr, 2) - 1) = crr
End With
End Sub
标准成本库.rar
(35.37 KB, 下载次数: 37)
|