• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Complicated nested if function!

Dear all,

I have the following problem: I want to create an excel function/vba script which can do the following:

According to two number in two cell it should produce a colour. So fe: if e1 = 2 and g1 = 3 in want "yellow" in cell j1. I tried to do this with a nested if fuction but this is going to be quite a hassle asthe values for both e1 and g1 can have 3 different values (which can lead to 9 different colours).

I tried to build a build a case VBA script but I cant seem to find AND option in the statements. Something like this does not work for example:

Case "E1" = 2 AND "F2" = 1
Range("S2") = "GREEN"

End Select

Anybody some suggestion on how i can achieve this? Help would be highly appreciated!

Dear regards,
Marc
 
Hi Marc ,

The syntax for the Select Case statement is different from what you have posted ; please look up the Excel help on this ; the following links may also help :

1. http://www.databison.com/vba-select-case-using-vba-select-case-statement-in-excel/

2. http://www.anthony-vba.kefra.com/vba/vbabasic3.htm

3. http://easyexcelvba.com/chapter_3.html

4. http://www.ozgrid.com/Excel/free-training/ExcelVBA1/excelvba1lesson13.htm

What you want can be done using multiple IF statements ; this is explained in some of the above links.

If you can give all the combinations , along with the cell addresses , we can post the exact code that will do the job.

Narayan
 
Back
Top