98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » If ElseIF Statements + And
If ElseIF Statements + And
Resolved · High Priority · Version 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 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
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Using Alt in Save Dialog BoxWhen you are saving (or opening) a file, try these; |