user16188014
user16188014

Reputation:

VBA code not entering else if and end if loop

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

Upvotes: 0

Views: 77

Answers (1)

BigBen
BigBen

Reputation: 49998

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

Upvotes: 1

Related Questions