if statements

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » If statements

If statements

resolvedResolved · Low Priority · Version 2003

Claire has attended:
Excel VBA Intro Intermediate course

If statements

How do you enter multiple if statements in VBA?

Edited on Fri 24 Oct 2008, 11:05

RE: If statements

Hi Claire

Thank you for your question regarding If Statements.

To use multiple Ifs in VBA you use an ElseIF. Be careful to make sure the ElseIf is one word. The syntax is very similar to the If line. You can have as many ElseIf lines inside your If statement as you like.

Example If Statement


Function Bonus(iSales As Integer, iTarget As Integer) As Integer
If iSales > iTarget Then
Bonus = 3000
ElseIf iSales = iTarget Then
Bonus = 2000
Else
Bonus = 250
End If

End Function


I hope that answers your question.

Laura GB

 

Training courses

 

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 tip:

How to select certain data in an Excel 2010 workbook

If you want to select the correct data set in a page full of data, the most accurate and efficient way of doing this is to use the ''Shift and Click'' technique.

For example: If you want to select all data in cells A2 to E10, then click on cell A2, hold down the Shift key and click on cell E10 and all the data you want to see is highlighted.

Keep holding down the Shift key and you can move from cell E10 to any other cell in the spreadsheet.

View all Excel hints and tips


Server loaded in 0.08 secs.