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

if elseif statements

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » If ElseIF Statements + And

If ElseIF Statements + And

ResolvedVersion 2010

Sif has attended:
Excel Advanced course

If ElseIF Statements + And

Hi there

I am trying to do If... ElseIf statement but cannot work out how to do these including and 'And' (I want to change the value of the cell AND the colour).

This is the code I have:

If (rngTrim <> ".") Then

If rngTrim > highPTile Then
rngTrim.Value = newHigh And rngTrim.Interior.ColorIndex = 37
ElseIf rngTrim < lowPTile Then
rngTrim.Value = newLow
End If


It is currently giving me 0s instead of returning the 'new' value (newHigh)

Thank you in advance!

RE: If ElseIF Statements + And

Hello Sif,

Thank you for your question. The AND and the OR functions are really meant to use in your IF or ELSEIF lines, to run more than one test on a cell. If you want to apply more than one action on a condition, rather write these expressions on separate lines.

I would suggest:

If rngTrim > highPTile Then
rngTrim.Value = newHigh
rngTrim.Interior.ColorIndex = 37

ElseIf rngTrim < lowPTile Then
rngTrim.Value = newLow

End If

I hope this works.

Kind regards
Marius Barnard
Best STL

Fri 7 Aug 2015: Automatically marked as resolved.

 

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:

Create a unique items table from a duplicating table

1. Ensure that your list has column headings
2. Select the entire list
3. From the menu bar, select DATA, FILTER, ADVANCED FILTER
4. Select "Filter the list, in place", and tick the "Unique Records Only" box
5. Click OK, filtered list appears.

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.1 secs.