Loop

O

oscarooko

Hello,
I need a loop for my code. I have this code, but it will only check if
the conditions are true for the first row, assigns a grade for teh row,
and then it terminates. I need it to go through all rows irrespective
of "how many" they are. Someone help!

Sub Oscar()
Dim grade As String
Dim FICO As String
Dim Lien As String
Dim LTV As String
Dim DTI As String

FICO = Sheet3.Range("U2").Value
Lien = Sheet3.Range("AA2").Value
LTV = Sheet3.Range("S2").Value
DTI = Sheet3.Range("V2").Value

If (FICO > 700 And Lien = 1 And LTV < 90 And DTI <= 45) Or (FICO > 720
And Lien = 1 And LTV < 95 And DTI <= 45) Then

grade = "Prime"
Else

If (FICO > 650 And Lien = 1 And LTV < 95 And DTI <= 45) Or (FICO >= 680
And Lien = 1 And LTV < 95 And DTI <= 50) Or (FICO >= 680 And Lien = 2
And LTV < 95 And DTI <= 50) Then
grade = "AA"

Else
If (FICO >= 600 And Lien = 1 And LTV < 100 And DTI <= 50) Or (FICO >=
620 And Lien = 2 And LTV <= 95 And DTI <= 45) Then
grade = "A+"

Else: grade = "FAIL"


End If
End If
End If
Sheet3.Range("L2").Value = grade
End Sub
 
G

Guest

Dim Counter as Long

for counter = 0 to Sheet3.Range("U65000").End(XLUp).Row - 2

''all your code here

next counter

works for all rows where there is a value in U

add offset to all your range refernces

ie...Sheet3.Range("L2").Offset(counter,0).Value = grade
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

VB code in Excel 4
Help 3
Logic and Loop Code 1
if statement conditions 6
index match 6
Calculation 2
vba range in vlookup 4
make selection in listbox html with vba 7

Top