If..Then or Case Else

I am using the code below in a command button click event. It works. So my question is there a better way to do this - like using the Case...Else which I am not "yet" comfortable with?

 Dim QtrTotal As Integer							
     QtrTotal = 1571							
     If Range("B7") <> QtrTotal Then							
        MsgBox "1st Qtr Total Hamburgers is incorrect!", vbOKOnly, "Incorrect Answer"							
Exit Sub							
End If							
     QtrTotal = 1271							
     If Range("C7") <> QtrTotal Then							
        MsgBox "1st Qtr Total Milk Shakes is incorrect!", vbOKOnly, "Incorrect Answer"							
Exit Sub							
End If							
     QtrTotal = 238							
     If Range("D7") <> QtrTotal Then							
        MsgBox "1st Qtr Total Salads is incorrect!", vbOKOnly, "Incorrect Answer"							
Exit Sub							
End If							
     QtrTotal = 642		              					
     If Range("E7") <> QtrTotal Then							
        MsgBox "1st Qtr Total Drinks is incorrect!", vbOKOnly, "Incorrect Answer"							
Exit Sub							
End If							

Open in new window

Frank FreeseAsked:
Who is Participating?
KimputerConnect With a Mentor Commented:
You keep testing different cells with different qrtotals.
On first sight, one might think a case of qrtotals would be sufficient, but it's actually not.
Your code should be as it is. You could put it all in an if then, elseif, elseif, elseif else, but it doesn't help that much for coding or readability reasons.
Frank FreeseAuthor Commented:
thanks...I wasn't heading to la-la land
I agree with Kimputer.

I mean, you could use a Case...but then you'd have to update some variable for the cell reference...probably not worth it (and over-complicating things).
Frank FreeseAuthor Commented:
thanks for the affirmation
appreciate it
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.