1

I have the below loop written, however I am having issues with the code entering the else if loop and to have the loop until (end if) the ranges equal each other. Essentially I want the loop to add 2 to the cells that contain "Corporates" first and afterwards add 1 to the cells that have a the number 2.

Dim x As Long
Dim V As Variant

V = Cells(Rows.Count, 1).End(xlUp).Row
JV = Range("J" & Rows.Count).End(xlUp).Row
For x = 1 To V
If Cells(x, 2).Value = "Corporates" Then
Cells(x, 7).Value = Cells(x, 7).Value + 1
    
ElseIf Cells(x, 12).Value < "3%" And Cells(x, 2).Value = "Corporates" Then
Cells(x, 7).Value = Cells(x, 7).Value + 1
    
End If
Range("J" & JV + 3).Value = Range("J" & JV + 2).Value
 
Next x
End Sub
1
  • 2
    ElseIf won't trigger since it has the same requirement as the If. So either the If triggers, or none of them. Cells(x, 12).Value < "3%" also probably won't behave as you'd expect since the "3%" is a string, and not a numerical value. Commented Jun 30, 2021 at 20:46

1 Answer 1

1

Use a nested If instead of ElseIf

I'm guessing that < "3%" should be < 0.03 ("3%" is text, not a number).

If Cells(x, 2).Value = "Corporates" Then
    If Cells(x, 12).Value < 0.03 Then
        Cells(x, 7).Value = Cells(x, 7).Value + 2
    Else
        Cells(x, 7).Value = Cells(x, 7).Value + 1
    End If
End If
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.