# Need VBA Code for the below scenario

#### Dinesaaa

##### New Member
Hey Guys,

Below is the scenario to write VBA code:-

> If Score is > 900
> If Income is > 600000
> If Occupation = "Salaried" and Income > 500000
> If Marital Status = "Single"
> If Own house = "yes"

1, If any one of the above criteria met result should be "Loan Eligible"
2, If any one of the above criteria not met "Not Eligible"

Below is my code where "Not Eligible" is not working:-

Function Loan(Cibilscore As Double, Ownhouse As String, Occupation As String, Marritalstatus As String, Income As Double)
If Cibilscore > 900 Then
If LCase(Ownhouse) = "yes" Then
If LCase(Occupation) = "salaried" And Income > 60000 Then
If LCase(Marritalstatus) = "single" Then
Loan = "Eligible"
End If
End If
End If
Else
Loan = "Not Eligible"
End If
End Function

### Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

#### mrhstn

##### Active Member
You can set loan to not eligible as default then change it if the criteria are met.

Code:
``````Function Loan(Cibilscore As Double, Ownhouse As String, Occupation As String, Marritalstatus As String, Income As Double)
Loan = "Not Eligible"
If Cibilscore > 900 Then
If LCase(Ownhouse) = "yes" Then
If LCase(Occupation) = "salaried" And Income > 60000 Then
If LCase(Marritalstatus) = "single" Then
Loan = "Eligible"
End If
End If
End If
End If
End Function``````

#### Dinesaaa

##### New Member
I tried the below code but not working???

Function Loaneligibiltycheck(Cibilscore As Double, Ownhouse As String, Occupation As String, Martialstatus As String, Income As Double)
Loaneligibiltycheck = "Not Eligible"
If Cibilscore >= 900 Then
If LCase(Ownhouse) = "yes" Then
If LCase(Occupation) = "salaried" And Income >= 600000 Then
If LCase(Martialstatus) = "single" Then
Loaneligibiltycheck = "Eligible"
End If
End If
End If
End If

End Function

#### JumpingCrab

##### Board Regular
Your selection criterion is somewhat ambiguous. Assuming you mean the following:
1. Any one or more of the criteria met: "Eligible"
2. None of the criteria met: "Not Eligible"

Then the following code will work:

Code:
``````Function Loan(Cibilscore As Double, Ownhouse As String, Occupation As String, Marritalstatus As String, Income As Double)
If Cibilscore > 900 Then
Loan = "Eligible"
ElseIf Income > 600000 Then
Loan = "Eligible"
ElseIf LCase(Ownhouse) = "yes" Then
Loan = "Eligible"
ElseIf LCase(Occupation) = "salaried" And Income > 500000 Then
Loan = "Eligible"
ElseIf LCase(Marritalstatus) = "single" Then
Loan = "Eligible"
Else
Loan = "Not Eligible"
End If
End Function``````

#### Dinesaaa

##### New Member
Thank you so much It works.

#### mrhstn

##### Active Member
As an alternative

Code:
``````Function LoanE(Cibilscore As Double, Ownhouse As String, Occupation As String, Marritalstatus As String, Income As Double)
Dim test As Integer
test = (Cibilscore > 900) * (Income > 600000) * (LCase(Ownhouse) = "yes") * ((LCase(Occupation) = "salaried") + (Income > 500000)) * (LCase(Marritalstatus) = "single")
LoanE = IIf(test = True, "Eligible", "Not Eligible")
End Function``````

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,167,813
Messages
5,855,785
Members
431,763
Latest member
AlexisChch

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back