|
楼主 |
发表于 2013-7-16 21:34
|
显示全部楼层
jsxjd 发表于 2013-7-14 21:38
估计楼主初次接触VBA,简单点,想实现什么功能?
Sub 右()
Dim l, b#, I%
I = 4
Do
l = Cells(I, 1)
If 17371.6 <= l And l <= 17500.85 Then
b = 20.311 + (l - 17371.6) * 2 / 1000
ElseIf 17500.85 <= l And l <= 17518 Then
b = 20.57 + (l - 17500.85) * 2 / 1000 + (l - 17500.85) ^ 2 / (2 * 5000)
ElseIf 17518 <= l And l <= 17535.15 Then
b = 20.633 + (l - 17518) * 8.86 / 1000 + (l - 17518) ^ 2 / (2 * 5000)
ElseIf 17535.15 <= l And l <= 17700 Then
b = 20.756 + (l - 17535.15) * 8.86 / 1000
ElseIf 17700 <= l And l <= 17707.98 Then
b = 22.217 + (l - 17700) * 8.86 / 1000 - (l - 17700) ^ 2 / (2 * 5000)
ElseIf 17707.98 <= l And l <= 17714.68 Then
b = 22.283 + (l - 17707.98) * 6.18 / 1000 - (l - 17707.98) ^ 2 / (2 * 5000)
ElseIf 17714.68 <= l And l <= 17817.85 Then
b = 22.329 + (l - 17714.68) * 6.18 / 1000
ElseIf 17817.85 <= l And l <= 17878.3 Then
b = 22.966 + (l - 17817.85) * 6.18 / 1000 + (l - 17817.85) ^ 2 / (2 * 5000)
ElseIf 17878.3 <= l And l <= 17938.75 Then
b = 22.974 + (l - 17878.3) * 18 / 1000 + (l - 17878.3) ^ 2 / (2 * 5000)
ElseIf 17938.75 <= l And l <= 17988.953 Then
b = 22.252 - (l - 17938.75) * 18 / 1000
Else
MsgBox "超出里程范围"
End If
Cells(I, 2) = b
I = I + 1
Loop Until Cells(I, 1) = ""
End Sub
现在公式都对了,可是进行某些运算时结果却不对! |
|