Need help with a formula that I need to ignore any colored cells

Phantasm

Board Regular
Joined
Nov 2, 2007
Messages
58
I have a formula to prioritize jobs on a worksheets that takes into account the days remaining until the jobs due date & also the operations of the job. I quantify each operation to a number that equals the days that I think the operation will take. Here is the formula:

=SUM(INT(E2-TODAY()))-(SUM(COUNTIF(G2:N2,{"SAW","3-AXIS","BP","MILL","BLANCHARD","RAL *","HARDEN","ASSEMBLY","BLACK ZINC","BRIGHT ZINC","BEND","BLACK ANODIZE","KEYSLOT","SPLINE","SAND","HELICOIL","CLEAR ANODIZE","WILLIAMS","WELD","LATHE","EPI"})*{0.5,1,1,1,5,5,2,0.5,1,1,3,5,5,5,0.5,0.2,1,5,2,1,5}))

E2 = Due date
G2:N2 = Job operations (example: 3-axis - Bend - BP - Black Zinc)

What I need this formula to do is to ignore any cells that are filled with any color. This is because as operations are completed, I fill that operations cell with a color.

I know excel cant check things by cell color, but if I can do something by making a VBA command, that works for me. Thanks!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I think I can use something like:

If Range("A1").Interior.Pattern <> xlNone Then

But Im not sure how to format it for the use I need.
 
Upvote 0
Whats throwing me off is how do I reference the cells I need to evaluate...Like in the first line, the calculation is done in O2 with E2 & G2:N2 being the cells with the data. Then I need to do it for each row, so O3 evaluates E3 & G3:N3 and so on.
 
Upvote 0
You could create a function in VBA that would give you a TRUE/FALSE response to the colour and then use that in your formula...

i.e.

Public Function coloured_cell(tgt As Range)


If tgt.Interior.ColorIndex = xlNone Then
coloured_cell = False
Else
coloured_cell = True
End If


End Function
 
Upvote 0
You could create a function in VBA that would give you a TRUE/FALSE response to the colour and then use that in your formula...

i.e.

Public Function coloured_cell(tgt As Range)


If tgt.Interior.ColorIndex = xlNone Then
coloured_cell = False
Else
coloured_cell = True
End If


End Function

But how would I get it to get the target cells? I need this calc at the end of each row. G2:N2 is the target for the first line and O2 is where this calculation would happen for that line. Then the next row would have G3:N3 for the target with O3 being the calculation?
 
Upvote 0
If you copy the function code into a VBA module, it becomes a function (like any other function in the workbook).

In the workbook, you would need to type in

=coloured_cell(G2:N2)

This would give you a TRUE / FALSE if any of the cells have a coloured background. (it will return true even if only 1 cell is coloured).

For your example formula, you could wrap it in an IF function....

=if(coloured_cell(G2:N2)=TRUE,SUM(INT(E2-TODAY()))-(SUM(COUNTIF(G2:N2,{"SAW","3-AXIS","BP","MILL","BLANCHARD","RAL *","HARDEN","ASSEMBLY","BLACK ZINC","BRIGHT ZINC","BEND","BLACK ANODIZE","KEYSLOT","SPLINE","SAND","HELICOIL","CLEAR ANODIZE","WILLIAMS","WELD","LATHE","EPI"})*{0.5,1,1,1,5,5,2,0.5,1,1,3,5,5,5,0.5,0.2,1,5,2,1,5})),"")
 
Upvote 0
If you copy the function code into a VBA module, it becomes a function (like any other function in the workbook).

In the workbook, you would need to type in

=coloured_cell(G2:N2)

This would give you a TRUE / FALSE if any of the cells have a coloured background. (it will return true even if only 1 cell is coloured).

For your example formula, you could wrap it in an IF function....

=if(coloured_cell(G2:N2)=TRUE,SUM(INT(E2-TODAY()))-(SUM(COUNTIF(G2:N2,{"SAW","3-AXIS","BP","MILL","BLANCHARD","RAL *","HARDEN","ASSEMBLY","BLACK ZINC","BRIGHT ZINC","BEND","BLACK ANODIZE","KEYSLOT","SPLINE","SAND","HELICOIL","CLEAR ANODIZE","WILLIAMS","WELD","LATHE","EPI"})*{0.5,1,1,1,5,5,2,0.5,1,1,3,5,5,5,0.5,0.2,1,5,2,1,5})),"")


Thats close, but I need to evaluate each cell seperately. If it sees 1 colored cell in the range, it stops. Is there a way I can code the counting to be done in the function? Something like:

If tgt.Interior.ColorIndex = xlNone Then
coloured_cell = False
add the value of all the non colored cells in the range with SAW = .5, 3-axis = 1...
Else
coloured_cell = True
all colored cell values = 0
End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,217
Members
452,619
Latest member
Shiv1198

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Back
Top