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

if statements

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

No Zeros

Want all the zeros in your worksheet to appear blank? Choose Tools/Options, Click on the View Tab, Deselect the Zero Values Option, Click OK.
Easy wasn't it? But be aware that these cells are not actually blank, they still contain the value zero. This is important because certain functions (ie AVERAGE) make a distinction between blank cells and those with a zero value.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.