|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
利息单没有用函数,上传vba代码:
Private Sub CommandButton1_Click()
If TextBox1.Value <> "" And TextBox1.Value <> 0 And ComboBox7.Value <> "" Then
T1 = ComboBox1 & "-" & ComboBox2 & "-" & ComboBox3
T2 = ComboBox4 & "-" & ComboBox5 & "-" & ComboBox6
If Evaluate("ISERROR(MONTH(""" & T1 & """))") Then
MsgBox "起息日期填写错误!", vbExclamation, "酷e提示:"
Else
If Evaluate("ISERROR(MONTH(""" & T2 & """))") Then
MsgBox "截止日期填写错误!", vbExclamation, "酷e提示:"
Else
Range("BG4") = T1
Range("BG5") = T2
PT1 = Evaluate("DATEVALUE(""" & T1 & """)")
PT2 = Evaluate("DATEVALUE(""" & T2 & """)")
PT3 = Evaluate("DATEVALUE(""" & Range("Q6") & """)")
PT4 = Evaluate("DATEVALUE(""" & Range("Q" & Range("BK1") & "") & """)")
If PT1 < PT3 Then
MsgBox "起息日期不能早于建账日:" & Label9, 64, "酷e提示:"
ElseIf PT1 > PT4 Then
MsgBox "起息日期不能晚于当前账期:" & Label10, 64, "酷e提示:"
ElseIf PT2 < PT1 Then
MsgBox "截止日期不能早于起息日!", 64, "酷e提示:"
ElseIf PT2 > PT4 Then
If Range("W" & Range("BK1") & "").Value = 0 Then
MsgBox "本账期末无余额,后期无需计息,请将截止日设到账期最后一天!", 64, "酷e提示:"
Else
If PT2 > Evaluate("DATEVALUE(""" & Sheets("凭证").Range("G2") & """)") Then
ASD1 = MsgBox("截止日期超出当前账期! 确定预计利息吗?", 65, "酷e提示:")
If ASD1 = 1 Then
TT1 = 1
End If
Else
TT1 = 1
End If
End If
Else
TT1 = 1
End If
End If
If TT1 = 1 Then
If TextBox4.Value <> "" And TextBox4.Value > 0 And ComboBox7.Value = "全部余额" Then
MsgBox "预设了无息天数,取数不能再选""全部余额"",请重新设置!", 64, "酷e提示:"
Else
Dim k As Long
For k = 6 To Range("BK1").Value
T0 = Range("Q" & k & "").Value
PT0 = Evaluate("DATEVALUE(""" & T0 & """)")
If PT0 > PT1 Then
TT = Range("W" & k - 1 & "").Value
If ComboBox7.Value = "应收余额" And TT < 0 Then
TT = 0
ElseIf ComboBox7.Value = "应付余额" And TT > 0 Then
TT = 0
End If
If PT0 <= PT2 Then
T01 = Range("Q" & k - 1 & "").Value
If T4 = "" Then
T4 = TT
T3 = PT0 - PT1
Else
T3 = PT0 - Evaluate("DATEVALUE(""" & T01 & """)")
End If
T4 = T4 + TT * T3
If PT0 = PT2 Then
Exit For
End If
Else
T02 = Range("Q" & k - 1 & "").Value
T10 = PT2 - Evaluate("DATEVALUE(""" & T02 & """)")
T11 = PT2 - PT1 + 1
T12 = Evaluate("MIN(" & T10 & "," & T11 & ")")
T4 = T4 + TT * T12
Exit For
End If
ElseIf PT0 = PT1 Then
If T4 = "" Then
If PT0 = PT3 Then
T4 = Range("W" & k & "").Value
Else
T4 = Range("W" & k - 1 & "").Value
End If
If ComboBox7.Value = "应收余额" And T4 < 0 Then
T4 = 0
ElseIf ComboBox7.Value = "应付余额" And T4 > 0 Then
T4 = 0
End If
End If
End If
Next k
If PT2 > PT4 Then
TT1 = Range("W" & Range("BK1") & "").Value
If ComboBox7.Value = "应收余额" And TT1 < 0 Then
TT1 = 0
ElseIf ComboBox7.Value = "应付余额" And TT1 > 0 Then
TT1 = 0
End If
T13 = PT2 - PT4
T4 = T4 + TT1 * T13
End If
If TextBox4.Value <> "" And TextBox4.Value > 0 Then
kk = Evaluate("MIN(" & k & "," & Range("BK1") & ")") + 1
Dim k1 As Long
For k1 = 1 To kk - 7
T01 = Range("Q" & kk - k1 & "").Value
PT01 = Evaluate("DATEVALUE(""" & T01 & """)")
If PT01 < PT2 Then
If PT01 >= PT1 And PT2 - PT01 - TextBox4.Value > 0 Then
If ComboBox7.Value = "应收余额" Then
T5 = T5 + Range("U" & kk - k1 & "")
ElseIf ComboBox7.Value = "应付余额" Then
T5 = T5 - Range("V" & kk - k1 & "")
End If
Else
If PT01 < PT1 Then
PT02 = Evaluate("MIN(" & PT2 - PT1 + 1 & "," & TextBox4.Value - PT1 + PT01 + 1 & ")")
If PT02 > 0 Then
If ComboBox7.Value = "应收余额" Then
T51 = T51 + Range("U" & kk - k1 & "") * PT02
ElseIf ComboBox7.Value = "应付余额" Then
T51 = T51 - Range("V" & kk - k1 & "") * PT02
End If
Else
Exit For
End If
Else
PT03 = Evaluate("MIN(" & PT2 - PT1 + 1 & "," & PT2 - PT01 & ")")
If ComboBox7.Value = "应收余额" Then
T52 = T52 + Range("U" & kk - k1 & "") * PT03
ElseIf ComboBox7.Value = "应付余额" Then
T52 = T52 - Range("V" & kk - k1 & "") * PT03
End If
End If
End If
End If
Next k1
T4 = T4 - T5 * TextBox4.Value - T51 - T52
T9 = Application.Round(T4 * TextBox1.Value / 100 / ComboBox8.Value, 2)
If ComboBox7.Value = "应收余额" And T4 < 0 Then
MsgBox "扣除" & TextBox4.Value & "天账期后计算结果为应付利息" & -T9 & "元,应收利息0元!", 64, "酷e提示:"
T4 = 0
ElseIf ComboBox7.Value = "应付余额" And T4 > 0 Then
MsgBox "扣除" & TextBox4.Value & "天账期后计算结果为应收利息" & T9 & "元,应付利息0元!", 64, "酷e提示:"
T4 = 0
End If
End If
TextBox3.Value = T4
End If
End If
End If
Else
If ComboBox7.Value = "" Then
MsgBox "请设置取数方法!", 64, "酷e提示:"
UserForm9.ComboBox7.SetFocus
Else
MsgBox "请输入年化利率!", 64, "酷e提示:"
UserForm9.TextBox1.SetFocus
End If
End If
End Sub |
|