Solved

If..Then or Case Else

Posted on 2014-03-24
4
218 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
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
Comment Utility
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
Comment Utility
thanks...I wasn't heading to la-la land
0
 
LVL 3

Expert Comment

by:englanddg
Comment Utility
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
Comment Utility
thanks for the affirmation
appreciate it
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now