mardi 4 octobre 2016

VBA Ranking Criteria Macro - Else Without If Error

I am trying to make a macro that returns a given rank depending on the value in a cell. The value it is based on (B24) would determine the ranking and place it in B26. Below is the ranking and the code I am using. Ex. Values with over 2B should result in "1". How can I get this to work? I am currently getting "Compile error: Else without if"

Sub Criteria()

On Error GoTo catch_error

Worksheets("Sheet1").Activate
Dim score As Integer, result As String
score = Range("B24").Value

If score > 2000000000 Then result = "1"

ElseIf score >= 1500000000 And score <= 1999999999.99 Then result = "2"

ElseIf score >= 500000000 And score <= 1499999999.99 Then result = "3"

ElseIf score >= 250000000 And score <= 499999999.99 Then result = "4"

ElseIf score < 249999999.99 Then result = "Out Of Scope"

result = Range("B26").Value

Exit Sub

catch_error:
MsgBox "Some Error Occurred"
End Sub

Aucun commentaire:

Enregistrer un commentaire