98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Nested Ifs in VBA
Nested Ifs in VBA
Resolved · Low Priority · Version 2003
Dimitrios has attended:
Excel Advanced course
Excel VBA Intro Intermediate course
Nested Ifs in VBA
I had created a piece of code trying to test some data adn I had to use numerous if statements. Peter suggested that using the Case function would be better and more effiecient. How exactly can I replace Ifs with Cases?
RE: Nested Ifs in VBA
Hi Dimitrios,
Thank you for your question.
You start with 'Select Case' and the name of the variable.
E.g. Select Case MarkUp
Multiple conditions are handled by 'Case Is'.
E.g. Case Is MarkUp > 2000
Underneath each 'Case Is' you type the true answer.
E.g. Case Is MarkUp > 2000
Commission = MarkUp * 0.05
Case Is MarkUp > 1000
Commission = MarkUp * 0.03
Continue this pattern until all the conditions have been entered.
Use 'Case Else' to input the answer for all the remaining values not covered by the conditions.
E.g. Case Else
Commission = 0
Finally you need to close the Select command with:
E.g. End Select
I hope this answers your question.
Regards
Simon
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Create your own custom list on Excel 2010!If you know how to use the auto-fill option on Excel then why not create your own customs lists? |