我对 excel 中的 vba 仍然很陌生,并且在解决这个问题时遇到了困难。我真的很希望有人能告诉我我的代码哪里出错了,并为我提供尽可能简化的解决方案。非常感谢&真的很感激!
问: 贷款申请是根据客户的收入来评估的。我们应该使用 For-Next 函数和 IF 语句来显示以下批准状态:
客户的收入与各自的地位
60,000 以特价批准;>40,000 以标准费率批准;>24,000 等待经理批准;其他情况 拒绝申请
从excel的第2行开始,B列包含“客户收入”数字,Excel中C列包含“贷款申请状态”数字。
我的代码运行良好,如下所示:
Sub ForNext_If()
'CINCOME = Customer Income,Loan status= the application status, x = the row number, FinalRow= last row number
x = 2
For x = 2 To 11 Step 1
CINCOME = Cells(x, 2).Value
If CINCOME > 60000 Then
LOANSTATUS = "Approve with special rates"
ElseIf CINCOME > 40000 Then
LOANSTATUS = "Approve with standard rates"
ElseIf CINCOME > 24000 Then
LOANSTATUS = "Await manager's approval"
Else
LOANSTATUS = "Reject application"
End If
Cells(x, 4) = LOANSTATUS
Next
End Sub
但是,当我尝试使用 call 功能时,
Sub ForNext_If()
x = 2
For x = 2 To 11 Step 1
CINCOME = Cells(x, 2).Value
Call Calling
Cells(x, 4) = LOANSTATUS
Next
End Sub
Function Calling()
If CINCOME > 60000 Then
LOANSTATUS = "Approve with special rates"
ElseIf CINCOME > 40000 Then
LOANSTATUS = "Approve with standard rates"
ElseIf CINCOME > 24000 Then
LOANSTATUS = "Await manager's approval"
Else
LOANSTATUS = "Reject application"
End If
End Function
CINCOME 的值似乎无法转移到“调用”函数来确定贷款申请状态。T_T 到底出了什么问题?