Formula depending on the color of a cell to calculate values

keranali

Rules Violation
Joined
Oct 4, 2010
Messages
234
Office Version
  1. 365
Platform
  1. Windows
Good Day All can I calculate values based on the colors of a cell. Calculation will be.... For Cell BJ3....if BF3 is red then take BI3 and make it a negative value and For Cell BJ3... If BF3 is Green then take (BM2*BL2)-BI4

Cell Colours

the project 1.3.xlsm
BF
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Overview


Sample output

Cell Formulas
RangeFormula
BJ3BJ3=-BI3
BJ4BJ4=(BM2*BL2)-BI4
BI3:BI27BI3=$BM$2*$BN$2
Cells with Conditional Formatting
CellConditionCell FormatStop If True
BH3:BI28Expression=AND(BG3<>"",ISEVEN(BG3))textNO
BH3:BI28Expression=ISODD(BG3)textNO


Adjustable values

the project 1.3.xlsm
BLBMBN
234522
Overview
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
you are using conditional formatting for RED
using ISODD(BG3)

you could use that in a calculation in a different cell to do that
I'm assuming if not red , then green - or is there a green rule

otherwise , would need VBA to check cell colour and also update the value , i do not provide vba solutions here
 
Upvote 0
if this is based on ODD or EVEN numbers

then you can
SUM ODD numbers using
=SUM(B3:B10*(MOD(B3:B10,2)=1))

SUM EVEN numbers using
=SUM(B3:B10*(MOD(B3:B10,2)=0))

as you have 365 version it will apply the array
on older versions needs Control+Shift+Enter

OR Even rows and ODD rows
ODD ROWS
=SUMPRODUCT(B3:B17,MOD(ROW(B3:B17)+0,2))
EVEN ROWS
=SUMPRODUCT(B3:B17,MOD(ROW(B3:B17)+1,2))

Sum odd or Even numbers.xlsx
ABCDEFG
1Sum OddSum EvenSum ODD RowsSum EVEN roews
2716185
312
41
55
64
71
Sheet1
Cell Formulas
RangeFormula
C2C2=SUM(B3:B10*(MOD(B3:B10,2)=1))
D2D2=SUM(B3:B10*(MOD(B3:B10,2)=0))
F2F2=SUMPRODUCT(B3:B17,MOD(ROW(B3:B17)+0,2))
G2G2=SUMPRODUCT(B3:B17,MOD(ROW(B3:B17)+1,2))
 
Last edited:
Upvote 0
Its based on number selections maybe instead of colors I this number set can be used e.g

the project 1.3.xlsm
BJ
2Actual
314
433
55
632
735
816
924
1016
111
1235
1316
1426
1510
1636
1714
1817
1918
2025
2127
2215
238
241
257
2623
2712
2811
2930
3035
3127
3236
3326
3414
3510
Overview



the project 1.3.xlsm
AMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBH
3232611691731292724812152833361019213025
423261169173129272481215283336254111020
523261169173129272481215283336254111020
623261169173129272481215283336254111020
723261169173129272481215283336254111020
823261162591731292724812152836332743219
923261162591731292724812152836332743219
1023261162591731292724812152836332743219
1123261162591731292724812152836332743219
1223261259173116292781215242836331021134
1323261259173116292781215242836331021134
1423261259173116292781215242836331021134
1523261259173116292781215242836331021134
1623311226291512242572893361783313201827
1723311226291512242572893361783313201827
1823311226291512242572893361783313201827
1923311226291512242572893361783313201827
2023261931251719271681215242836331321527
2123261931251719271681215242836331321527
2223261931251719271681215242836331321527
2323261931251719271681215242836331321527
242326193127172529121681524284226103421
252326193127172529121681524284226103421
262326193127172529121681524284226103421
272326193127172529121681524284226103421
2823269311217252971681215242842214183519
2923269311217252971681215242842214183519
3023269311217252971681215242842214183519
3123269311217252971681215242842214183519
3223269311217252971681215242842234101932
3323269311217252971681215242842234101932
3423269311217252971681215242842234101932
3523269311217252971681215242842234101932
Overview



If a number from the actual table BJ3 is not listed in the larger table then make BM3 a negative value of the figure in BL3 and if the number is listed in larger list then allow this =($BP$2*$BO$2)-$BL$4
 
Upvote 0
I am trying to use this However its not working too well =IF(ISNUMBER(MATCH(BJ3,AM3:BH3,0)),-BL3,($AB$4*$AA$4)-$BLA$43+B3)
 
Upvote 0
in your example - all the numbers in BJ are listed in the larger table

I dont understand the yellow highlight

I have used a countif() to see if the number in BJ exists in the table and you will see from below it does
Book2
BJBK
2ActualCountif
3144
43321
554
6328
7354
81629
92433
101629
11133
12354
131629
142633
151017
163621
17144
181733
19188
202533
212712
221533
23833
24133
25733
262333
271233
28114
29301
30354
312712
323621
332633
34144
351017
Sheet1
Cell Formulas
RangeFormula
BK3:BK35BK3=COUNTIF($AM$3:$BH$35,BJ3)


We could use IF ( COUNTIF($AM$3:$BH$35,BJ3) = 0 , BJ3*-1 , ($BP$2*$BO$2)-$BL$4)
But that ($BP$2*$BO$2)-$BL$4 is fixed and will result in all the same answers , is the formula correct ?

I have also added a conditional formatting rule to show if the BJ number exists in the table
Book2
AMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBH
3232611691731292724812152833361019213025
423261169173129272481215283336254111020
523261169173129272481215283336254111020
623261169173129272481215283336254111020
723261169173129272481215283336254111020
823261162591731292724812152836332743219
923261162591731292724812152836332743219
1023261162591731292724812152836332743219
1123261162591731292724812152836332743219
1223261259173116292781215242836331021134
1323261259173116292781215242836331021134
1423261259173116292781215242836331021134
1523261259173116292781215242836331021134
1623311226291512242572893361783313201827
1723311226291512242572893361783313201827
1823311226291512242572893361783313201827
1923311226291512242572893361783313201827
2023261931251719271681215242836331321527
2123261931251719271681215242836331321527
2223261931251719271681215242836331321527
2323261931251719271681215242836331321527
242326193127172529121681524284226103421
252326193127172529121681524284226103421
262326193127172529121681524284226103421
272326193127172529121681524284226103421
2823269311217252971681215242842214183519
2923269311217252971681215242842214183519
3023269311217252971681215242842214183519
3123269311217252971681215242842214183519
3223269311217252971681215242842234101932
3323269311217252971681215242842234101932
3423269311217252971681215242842234101932
3523269311217252971681215242842234101932
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
AM3:BH35Expression=COUNTIF($BJ$3:$BJ$35,AM3)>0textNO


I'm afraid i'm really not following what you are after ......

perhaps you can answer the questions above and also give some expected results and why - perhaps on a much smaller set of data
 
Upvote 0
Ok sorry for the unclear request I tried redo the workbook and lay it out better.

This is the table of data where the sort will take place in a line row from AM3:BH3. when a number is manually inputted into BJ3 and that number does not appear in the row AM3:BH3, BM3 will multiply BL3* -1 however if the number appears in the row then it should do this =($AB$4*$AA$4)-BL4. see example below:

the project 1.3.xlsm
AMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJBKBLBM
21st2nd3rd4th5th6th7th8th9th10th11th12th13th14th15th16th17th18th19th20th21st22ndActualColourInvestmentProfit/Loss
323261169173129272481215283336101921302514220-220
42326116917312927248121528333625411102033220120
Overview
Cell Formulas
RangeFormula
BL3:BL4BL3=$AB$4*$AC$4
BM3BM3=-BL3
BM4BM4=($AB$4*$AA$4)-BL4
Cells with Conditional Formatting
CellConditionCell FormatStop If True
BK3:BL39Expression=AND(BJ3<>"",ISEVEN(BJ3))textNO
BK3:BL39Expression=ISODD(BJ3)textNO


And the line sort range AM3:BH3 should be dependent on a line count, if the line count should change to e.g 5 then the range will adjust to the 1st to the 5th number


the project 1.3.xlsm
AAABAC
3MutiplierNominal Line Count
4341022
Overview
 
Upvote 0
i'm just a little confused by some of the formulas you are using in the rows ....

BUT taking you at your word

you can use a countif() to see if the number is in the row

=IF(COUNTIF(AM3:BH3,BJ3)=0,BL3*-1,($AB3*$AA3)-BL3)

COUNTIF(AM3:BH3,BJ3)=0 , then the number is not in the row - and so BL3*-1
otherwise
($AB3*$AA3)-BL3

Now i have NOT fixed the ROW - so was not sure if
($AB3*$AA3)-BL3
was correct

but you can see the IF and change

I have also added conditional formatting
simple
AM3=$BJ3

BUT now with the line count, that gets a bit more complicated as that is changing a range based on a number in a different sheet
So the countif() will have to change

at the moment because in Linecount you have 22 we can use
COUNTIF(AM3:BH3,BJ3)=0

BUT if line count was 5 , then that would be
COUNTIF(AM3:AQ3,BJ3)=0

so i think we will need some sort of indirect() ... and columns / offset type of thing
will need to have a think about

if you could just check the $ in the formulas below

Book2
AMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJBKBLBM
21st2nd3rd4th5th6th7th8th9th10th11th12th13th14th15th16th17th18th19th20th21st22ndActualColourInvestmentProfit/Loss
323.0026.001.0016.009.0017.0031.0029.002.007.0024.008.0012.0015.0028.0033.0036.0010.0019.0021.0030.0025.0014.0000
423.0026.001.0016.009.0017.0031.0029.002.007.0024.008.0012.0015.0028.0033.0036.0025.004.0011.0010.0020.0033.0000
Sheet1
Cell Formulas
RangeFormula
BL3:BL4BL3=$AB$4*$AC$4
BM3:BM4BM3=IF(COUNTIF(AM3:BH3,BJ3)=0,BL3*-1,($AB3*$AA3)-BL3)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
AM3:BH4Expression=AM3=$BJ3textNO
 
Upvote 0
see previous post as well as this one

I have added the range based off the other sheet number

Many ways I guess to do this - I have chosen the below
But maybe OFFSET would be another choice

INDIRECT() is volatile - and so will update every time the sheet updates - which can slow things down
should be able to do with an index, but i could not make it work - so watch out , as i may change that , if i can to a Non-Volatile function if possible

i think this will work
=IF(COUNTIF( AM3:INDIRECT(ADDRESS(ROW(),38+overview!$AC$4)),BJ3)=0,BL3*-1,($AB3*$AA3)-BL3)

Using a sheet named overview and a cell AC4 to find the number of columns to count as a range

the 38 is the starting column 0 so its based on AL
and start at AM3
if a 5 was in the cell
then the range would be
AM3 to AQ3

row() gives the row() the formula is in

Book2
AMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJBKBLBM
21st2nd3rd4th5th6th7th8th9th10th11th12th13th14th15th16th17th18th19th20th21st22ndActualColourInvestmentProfit/Loss
323.0026.001.0016.009.0017.0031.0029.002.007.0024.008.0012.0015.0028.0033.0036.0010.0019.0021.0030.0025.0014.00220-220
423.0026.001.0016.009.0017.0031.0029.002.007.0024.008.0012.0015.0028.0033.0036.0025.004.0011.0010.0020.0033.0022011780
5
6
Sheet1
Cell Formulas
RangeFormula
BM3:BM4BM3=IF(COUNTIF( AM3:INDIRECT(ADDRESS(ROW(),38+overview!$AC$4)),BJ3)=0,BL3*-1,($AB3*$AA3)-BL3)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
AM3:BH4Expression=AM3=$BJ3textNO


Book2
AAABAC
3MutiplierNominal Line Count
4341022
overview



I have added to dropbox share the spreadsheet - BUT i only KEEP this on the share for a few days

 
Upvote 1
Solution

Forum statistics

Threads
1,215,371
Messages
6,124,529
Members
449,169
Latest member
mm424

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