nested ifs vba
Request a callback

We'll call during UK business hours

0207 987 3777

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.




Please browse our web site to find out more about
excel consultants and other Microsoft training courses.

Excel tip:

Fill formulae across a sheet

To copy a formula down a spreadsheet where there is data underneath, to the left or to the right of the formula, double-click on the fill handle. The fill handle is the little black cross that appears in the bottom right-hand corner of the formula cell. Unfortunately, no similar facility exists to copy formulae across the sheet.

One reasonably quick way to copy an existing formula across a sheet is to select the formula and the cells on the right to which you want to copy it. Then press Ctrl+R to copy the formula across the selected range, or, if you are menu-minded, use the Edit|Fill|Right command.

View all Excel hints and tips

Excel training
Course rating
4.7 stars - based on 24710 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