Calculation as per color of cell

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello Guys,

I am trying to get the result in sheet2 from sheet 1. If the cells in sheet one is colored, then it should display the amount less by one percent or else the whole amount as shown in the image.
Query for Match and calculate.xlsx
ABCDEFGHIJ
1Sheet 1NameAmountSheet 2NameAmount
2January1,000.00January990.00
3February2,000.00February2,000.00
4March3,000.00March3,000.00
5April4,000.00April3,960.00
6May1,500.00May1,500.00
7June2,500.00June2,500.00
8July3,500.00July3,500.00
9August4,500.00August4,455.00
10September5,500.00September5,445.00
11October6,500.00October6,500.00
12November7,500.00November7,500.00
13December4,500.00December4,500.00
14Sunday1,500.00Sunday1,485.00
15Monday2,500.00Monday2,500.00
16Tuesday3,500.00Tuesday3,500.00
17Wednesday4,500.00Wednesday4,455.00
18Thursday5,500.00Thursday5,500.00
19Friday6,500.00Friday6,500.00
20Saturday7,500.00Saturday7,500.00
Sheet1
Cell Formulas
RangeFormula
I18:J20,I2:I17,J15:J16,J11:J13,J6:J8,J3:J4J3=D3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C:CExpression=MATCH(C1,$M$1:$M$9,0)textNO
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
The figures in Column J are entered manually and the cells too are colored manually just to show what result I am trying to get and in which cells. If I change January to February in cell C2, then automatically he amount in column J2 should display 1000.
 
Upvote 0
How about this?

Code:
Sub Rajesh()
Dim lr As Long, i As Long, ct As Long
lr = Cells(Rows.Count, "C").End(xlUp).Row
For i = 2 To lr
 If 6 = Cells(i, "C").Interior.ColorIndex Then
 Cells(i, "J") = 0.9 * Cells(i, "D").Value
 Cells(i, "J").Interior.ColorIndex = 6
 Else
 Cells(i, "J") = Cells(i, "D").Value
 End If
Next i
End Sub
 
Upvote 0
@kweaver :

VBA Code:
Sub Rajesh()
'
    Dim lr As Long, i As Long, ct As Long
'
    lr = Cells(Rows.Count, "C").End(xlUp).Row
'
    For i = 2 To lr
        If 6 = Cells(i, "C").Interior.ColorIndex Then       ' Is it 6 or is it 27 ? Difficult to distinguish sometimes.
            Cells(i, "J") = 0.9 * Cells(i, "D").Value
            Cells(i, "J").Interior.ColorIndex = 6           ' Is it 6 or is it 27 ? Difficult to distinguish sometimes.
        Else
            Cells(i, "J") = Cells(i, "D").Value
        End If
    Next i
End Sub
 
Upvote 0
In both the codes I am getting 1000 in cell j2 which is supposed to show 990 as January is formatted by condiftional formatting.
 
Upvote 0
@kweaver :

VBA Code:
Sub Rajesh()
'
    Dim lr As Long, i As Long, ct As Long
'
    lr = Cells(Rows.Count, "C").End(xlUp).Row
'
    For i = 2 To lr
        If 6 = Cells(i, "C").Interior.ColorIndex Then       ' Is it 6 or is it 27 ? Difficult to distinguish sometimes.
            Cells(i, "J") = 0.9 * Cells(i, "D").Value
            Cells(i, "J").Interior.ColorIndex = 6           ' Is it 6 or is it 27 ? Difficult to distinguish sometimes.
        Else
            Cells(i, "J") = Cells(i, "D").Value
        End If
    Next i
End Sub
Please try and Use a single option in the code for non color and color cells. Its either white cell or conditional formatted with any other color cell.
 
Upvote 0
In both the codes I am getting 1000 in cell j2 which is supposed to show 990 as January is formatted by condiftional formatting.
As you can see from my sample a few posts up, I use

Code:
Cells(i, "J") = 0.9 * Cells(i, "D").Value

which takes 10% off (which is 90% on).
 
Upvote 0
Please try and Use a single option in the code for non color and color cells. Its either white cell or conditional formatted with any other color cell.
It’s conditional formatting with one single colour
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

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