|
Sub test()
Dim ylj_zy As Variant
Dim ylj_s As Variant
Dim ylg_x As Variant
sj_1 = CDate("2012/7/1")
sj_2 = CDate("2014/6/1")
sj_3 = CDate("2014/7/1")
sj_4 = CDate("2014/12/1")
sj_5 = CDate("2015/1/1")
sj_6 = CDate("2017/12/1")
sj_7 = CDate("2018/1/1")
sj_8 = CDate("2018/9/1")
sj_9 = CDate("2018/10/1")
sj_10 = CDate("2019/1/1")
bz_zy1 = 55
bz_zy2 = 70
bz_zy3 = 88
bz_s1 = 7
bz_s2 = 11.2
bz_s3 = 10.2
bz_x1 = 3
bz_x2 = 5.8
bz_x3 = 6.8
If (Range("b9") <= sj_2) And (Range("c9") <= sj_2) Then
ylj_zy = (DateDiff("m", Range("b9"), Range("c9")) + 1) * bz_zy1
ylj_s = "0"
ylj_x = "0"
End If
If (Range("b9") <= sj_2) And (sj_3 < Range("c9") <= sj_4) Then
ylj_zy = (DateDiff("m", Range("b9"), sj_2) + 1) * bz_zy1 + (DateDiff("m", sj_3, Range("c9")) + 1) * bz_zy2
ylj_s = "0"
ylj_x = "0"
End If
If (Range("b9") >= sj_3) And (Range("c9") <= sj_4) Then
ylj_zy = (DateDiff("m", Range("b9"), Range("c9")) + 1) * bz_zy2
ylj_s = "0"
ylj_x = "0"
End If
If (Range("b9") >= sj_5) And (sj_5 <= Range("c9") <= sj_6) Then
ylj_zy = (DateDiff("m", Range("b9"), Range("c9")) + 1) * bz_zy2
ylj_s = (DateDiff("m", Range("b9"), Range("c9")) + 1) * bz_s1
ylj_x = (DateDiff("m", Range("b9"), Range("c9")) + 1) * bz_x1
End If
If (Range("b9") <= sj_2) And (sj_5 <= Range("c9") <= sj_6) Then
ylj_zy = (DateDiff("m", Range("b9"), sj_2) + 1) * bz_zy1 + (DateDiff("m", sj_3, Range("c9")) + 1) * bz_zy2
ylj_s = (DateDiff("m", sj_5, Range("c9")) + 1) * bz_s1
ylj_x = (DateDiff("m", sj_5, Range("c9")) + 1) * bz_x1
End If
Range("d9") = ylj_zy
Range("e9") = ylj_s
Range("f9") = ylj_x
End Sub
标红的那一段本来不符合条件,不应该进行计算,结果if条件不成立都接着计算,导致计算结果与预期不一致,请高手看看,谢谢!
|
|