nested ifs vba
Request a callback

We'll call during UK business hours

Name:
Number:
0207 987 3777
STL

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Nested Ifs in VBA

Nested Ifs in VBA

resolvedResolved · Low Priority · Version 2003

Fri 21 Aug 2009, 15:45 replyReply Delegate Dimitrios said...

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?

For upcoming training course dates see: Pricing & availability

Mon 24 Aug 2009, 15:00 replyReply Trainer Simon said...

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


 

Excel tip:

Rotating Text in an Excel 2010 Worksheet

Maybe you want to draw attention to certain text or you just simply want to make your worksheet look more exciting!

One of the things you might consider is, rotating the text in a particular cell or set of cells.

1) Select a cell you would like to rotate
2) Click the ''Home'' tab in the Ribbon
3) Click ''orientation'' in the ''Alignment'' section
4) A pop up menu will appear with a few choices, if you want to decide yourself how many degrees to rotate the text, then click ''Format Cell Alignment.''

View all Excel hints and tips

Training courses
London & UK

Live dates & prices »

On-site training

60-second quote »

E-Learning

From £99 · Call us »

Mailing list

Sign up for latest offers »

 

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.



Excel training
Course rating
4.7 stars - based on 25492 reviews
Microsoft Certified Partner Institute of Leadership and Management - Certified Courses Learning and Performance Institute - Accredited Training Provider Security Seal verified by visa, mastercard securecard

Connect with us: Google+ · Facebook · Twitter · LinkedIn · Pinterest

2nd Floor, CA House, 1 Northey Street
Limehouse Basin, London, E14 8BT
United Kingdom

info@microsofttraining.net

Resources

X

Search