Creating Complex Functions in the Worksheet Formula Bar - THIS
Isn't the code below easier to understand and debug and comment???
Function (Cell1 as Range, Cell2 as Range)
IF (Cell ="Red" and Cell2 ="Yellow") then
Mycolor = "Orange"
else
IF (cell1 ="Scarlet" or Cell2="Crimson") then
Mycolor = "Red"
else
IF (cell1="Blue" or cell1 ="Navy") and (cell2 ="Yellow") then
Mycolor = "Green"
else
Mycolor = "Some other color" 'I'm from the USA, don't spell colour
with a U
end if
end if
end if
end function
"Smallweed" wrote:
Interesting way round to come at Excel but it happens...
Inside out really. Here's an example of a nested If function (tends to
shock and amaze programmers!). Stick it in C2 and experiment with colours (a
really useful tool is Tools, Formula Auditing, Evaluate Formula):
=IF(AND(A2="Red",B2="Yellow"),"Orange",IF(OR(A2="S carlet",B2="Crimson"),"Red",IF(AND(OR(A2="Blue",A2 ="Navy"),B2="Yellow"),"Green","Some other colour")))
The Ands and Ors are read outwards before the Ifs are evaluated [syntax of IF:
IF(condition, if true, if false)]
Hope that helps in some way!
"SteveM" wrote:
This may seem strange, but I code in VBA but never created complex
functions on a worksheet itself. Now it's driving me crazy trying to
embed functions in functions.
Is there some sort of trick there? Outside in? Inside out?
Or some kind of editing tool?
Thanks.
SteveM
|