# An If Statement based on colour?

#### aiden1983

##### Board Regular
I haven't tried it yet but is it possible to do an if statement based on colour? I want it to do a specific calculation in the colour is red and a diff one if it is blue etc. ie If the cell is red and the number 5 is in it then do x=10-5 if the cells is blue and the number 5 is in it then do x=20-5 etc. Is this possible?

### Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},\$Z\$1:\$Z\$99,\$Y\$1:\$Y\$99),2,False) to lookup Y values to left of Z values.
If the cells are coloured manually then you would need VBA code to do this.

Perhaps:
How is the cell colored? Manually or with Conditional Formatting?
lenze

It's definitely easier with VBA or if the cells are colored via conditional formatting, but it's possible with manual shading and no VBA.

You'd need to use GET.CELL though as outlined here: http://www.mrexcel.com/forum/showthread.php?t=20611

Or, more specifically, =GET.CELL(38,OFFSET(INDIRECT("rc",FALSE),0,1)) or similar in a named range

take a look at Chip Pearson function on color

http://www.cpearson.com/excel/colors.aspx

you could possibly use his functions with an if statement, I haven't tested that.

oh yes they are coloured manually and I will be using vba. Thanks for the help I will check out those links.

Aiden

Maybe something as simple as
Code:
``````Sub Fanugi()
Dim cl as Range
For Each cl in Range("\$A\$2:\$A" & Range("\$A\$65536").End(xlUp).Row)
Select Case cl.Interior.ColorIndex
Case 3 : Cells(cl.Row,2) = 10 - cl
Case 5 : Cells(cl.Row,2) = 20 - cl
'etc
Case Else:
End Select
Next cl
End Sub``````
lenze

Replies
1
Views
517
Replies
4
Views
293
Replies
1
Views
243
Replies
5
Views
339
Replies
2
Views
647

1,196,346
Messages
6,014,734
Members
441,843
Latest member
benji 71

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back