Sub 计算()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim i, n, w, j, a, b, arr, brr
[o1] = "金额": [p1] = "单价"
arr = [a1].CurrentRegion
brr = Sheets("价格表").[a1].CurrentRegion
'crr = Sheets("加价区").[a1].CurrentRegion
For i = 2 To UBound(arr)
'**************匹配单价*************
For n = 2 To UBound(brr) '大于3公斤计算
If brr(n, 1) = arr(i, 8) And InStr(brr(n, 3), arr(i, 11)) > 0 Then
a = arr(i, 13)
If a > 0 And a <= 0.5 Then arr(i, 15) = brr(n, 4): arr(i, 16) = brr(n, 4)
If a > 0.5 And a <= 1 Then arr(i, 15) = brr(n, 5): arr(i, 16) = brr(n, 5)
If a > 1 And a <= 1.5 Then arr(i, 15) = brr(n, 6): arr(i, 16) = brr(n, 6)
If a > 1.5 And a <= 2 Then arr(i, 15) = brr(n, 7): arr(i, 16) = brr(n, 7)
If a > 2 And a <= 2.5 Then arr(i, 15) = brr(n, 8): arr(i, 16) = brr(n, 8)
If a > 2.5 And a <= 3 Then arr(i, 15) = brr(n, 9): arr(i, 16) = brr(n, 9)
If a > 3 Then arr(i, 15) = a * brr(n, 10): arr(i, 16) = brr(n, 10)
'For c = 2 To UBound(crr) '加价区计算
'If arr(i, 8) = crr(c, 1) And arr(i, 11) = crr(c, 2) Then
'b = crr(c, 3)
'If a < 2 Then
'arr(i, 15) = arr(i, 15) + b
'Else
'arr(i, 15) = arr(i, 15) + a * b
'End If
'Exit For
'End If
'Next
End If
Next
Next
[a1].CurrentRegion = arr
MsgBox "计算完毕!", 48, "温馨提示!"
End Sub
给你一段代码参考吧 |