New to VBA: Block if without end if

I want to send the user an error message based on two different values on an excel sheet. I keep getting a "Block if without end if" error.

Sub Cellname()
'
' Cellname Macro

    If Range("E1").Value <> Range("G1").Value Then
        MsgBox "All Tier 2 Escalated Incidents are tracked."

    If Range("E1").Value > Range("G1").Value Then
        MsgBox "More Tier 2 Escalated ideas are currently being tracked than are present on the datasheet. Check Tracked Status."

    If Range("E1").Value < Range("G1").Value Then
        MsgBox "New Tier 2 Escalated ideas may be available. Check the datasheet"

    End If

End Sub

2 answers

  • answered 2018-01-11 19:58 user2731076

    You need to use ElseIf to add more than one condition to a single IF-THEN statement.

    If Range("E1").Value <> Range("G1").Value Then
        MsgBox "All Tier 2 Escalated Incidents are tracked."
    
    ElseIf Range("E1").Value > Range("G1").Value Then
        MsgBox "More Tier 2 Escalated ideas are currently being tracked than are present on the datasheet. Check Tracked Status."
    
    ElseIf Range("E1").Value < Range("G1").Value Then
        MsgBox "New Tier 2 Escalated ideas may be available. Check the datasheet"
    
    End If
    

    Otherwise add an End If after each If statement.

  • answered 2018-01-11 21:11 mooseman

    If you are doing an IF statement with no else and only one command, you don't need END IF at all. Although, I believe you may want ElseIF's to make this work logically. Just keep the code all one one line for each If statement like this:

     If Range("E1").Value <> Range("G1").Value Then MsgBox "All Tier 2 Escalated Incidents are tracked."
    
        If Range("E1").Value > Range("G1").Value Then MsgBox "More Tier 2 Escalated ideas are currently being tracked than are present on the datasheet. Check Tracked Status."
    
        If Range("E1").Value < Range("G1").Value Then MsgBox "New Tier 2 Escalated ideas may be available. Check the datasheet"