Sub sxdtest()
arr = Sheet1.Range("a3").CurrentRegion
On Error Resume Next
For i = 2 To UBound(arr)
If arr(i, 1) & arr(i, 3) <> arr(i + 1, 1) & arr(i + 1, 3) Then
arr(i, 8) = 0
n = n + Val(arr(i, 5))
arr(i, 8) = m
If arr(i, 4) = "偏遠" Then arr(i, 8) = arr(i, 8) + 30
If n < 4 Then arr(i, 8) = arr(i, 8) + 300
If n >= 4 Then arr(i, 8) = arr(i, 8) + 80 * n
If InStr(arr(i, 7), "特大") > 0 Then arr(i, 8) = arr(i, 8) + 80 * 1.5 * Val(arr(i, 5))
If InStr(arr(i, 7), "超重") > 0 Then arr(i, 8) = arr(i, 8) + 120 * Val(arr(i, 5))
n = 0
m = 0
Else
n = n + Val(arr(i, 5))
If InStr(arr(i, 7), "特大") > 0 Then m = m + 80 * 1.5 * Val(arr(i, 5))
If InStr(arr(i, 7), "超重") > 0 Then m = m + 120 * Val(arr(i, 5))
End If
Next
Sheet1.Range("a3").CurrentRegion = arr
End Sub |