[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

If..Then or Case Else

Posted on 2014-03-24
4
Medium Priority
?
235 Views
Last Modified: 2014-03-24
Folks,
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"							
        Worksheets("2DLine").Range("B7").ClearContents							
        Range("B7").Select							
Exit Sub							
End If							
     QtrTotal = 1271							
     If Range("C7") <> QtrTotal Then							
        MsgBox "1st Qtr Total Milk Shakes is incorrect!", vbOKOnly, "Incorrect Answer"							
        Worksheets("2DLine").Range("C7").ClearContents							
        Range("C7").Select							
Exit Sub							
End If							
     QtrTotal = 238							
     If Range("D7") <> QtrTotal Then							
        MsgBox "1st Qtr Total Salads is incorrect!", vbOKOnly, "Incorrect Answer"							
        Worksheets("2DLine").Range("D7").ClearContents							
        Range("D7").Select							
Exit Sub							
End If							
     QtrTotal = 642		              					
     If Range("E7") <> QtrTotal Then							
        MsgBox "1st Qtr Total Drinks is incorrect!", vbOKOnly, "Incorrect Answer"							
        Worksheets("2DLine").Range("E7").ClearContents							
        Range("E7").Select							
Exit Sub							
End If							

Open in new window

0
Comment
Question by:Frank Freese
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 36

Accepted Solution

by:
Kimputer earned 2000 total points
ID: 39952129
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.
0
 

Author Closing Comment

by:Frank Freese
ID: 39952151
thanks...I wasn't heading to la-la land
0
 
LVL 3

Expert Comment

by:englanddg
ID: 39952157
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).
0
 

Author Comment

by:Frank Freese
ID: 39952225
thanks for the affirmation
appreciate it
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question