I have a range of cell (A5: Z50).
A, C, E, G, H cell colour was set to "Light Blue" (Done).
The user will need to make changes or input new data into the remaining cell as and when required.
I want the cells (except the above) to change to "Light Green" (I managed to use Conditional Formatting to set it) when data are input/keyed in.
and When a comment is added, I want the cell colour to change to "Light Red".
How can I achieve this?
Managed to add a function and applied the conditional format to my worksheet.
This will help in solving 2 Conditional Format set.
Cell colour will be changed to Green when Text keyed in.
Cell colour will be changed to Another Colour when comments added.
Function IsComm(CellComm As Range) As Boolean
Application.Volatile
IsComm = False
If Not CellComm.Comment Is Nothing Then IsComm = True
End Function
Related
I don’t want to use conditional formatting because I need a different value as the text in the cell (not what the color values apply to).
Column E is status (at risk/on track/needs improvement)
Column I is trend, displayed as arrows (Unicode text)
Column J is blank
I would like the color of the corresponding cells to be based on Column E text “Needs Improvement” in red, “At Risk” in yellow, and “On Track” in green.
So - in J2 through J13, I need the color only from the E2:E13 status and the trend arrows from I2:I13
I know this has been asked before in one way or another, but I can’t figure out the conditional formatting in VBA for some reason. Im sorry
Conditional formatting doesn’t work, I was trying to pull conditional colors from column E, but the only code I could get to work couldn’t integrate conditional formatting colors (it had to be true cell colors)
Below are the 4 sets of conditional formatting I used to accomplish the below example. I did not know what your trend data looks like so you'll need to adjust that to fit. To note, the formula in column J is ["=I" & row], so it's pulling over the same values. Those are hidden with the icon formatting. ::
Where RG = range("J2:J18")
Colour:="Red" while [=$E2="At Risk"]
Colour:="Yellow" while [=$E2="Needs Improvement"]
Colour:="Green" while [=$E2="On Track"]
Shape:="Icon Set" [checkmark] Show Icon Only
Example of formatting:
Example of result:
Let me know if any of that doesn't make sense.
I need to add values of a range when its contents are of a certain font color (e.g., black). What I have is a a table where I am conditionally formatting the color of values. For e.g., if the "Status =Carry Over" then I am coloring the row Red. (see attachment).
Now, after the conditional formatting, I want to sum all the number values under a specific column that are NOT in red color.
I have a piece of vba code to add such values, but the problem is, the conditional coloring is throwing the code off. As long as I am manually coloring the rows, the code is ignoring the red rows. If I use the conditional coloring option, then even the colored rows are taken into account.
I am calling the below UDF using this formula =ConditionalColorSum(C2:C30)
Public Function ConditionalColorSum(rnge As Range) As Double
' Total only cells with red font numbers
Application.Volatile
Dim Total As Double, cl As Range
Total = 0
For Each cl In rnge.Cells
If cl.Font.Color = vbRed Then 'Change 'vbRed' to the color you want
Total = Total + cl.Value
End If
Next
ConditionalColorSum = Total
End Function
The Conditional formatting formula looks like above:
As per THIS
Actions such as changing the conditional formatting or table style of a range can cause what is displayed in the current user interface to be inconsistent with the values in the corresponding properties of the Range object. Use the properties of the DisplayFormat object to return the values as they are displayed in the current user interface.
The only way to get the color due to conditional formatting is to use DisplayFormat
If cl.DisplayFormat.Font.Color = vbRed Then
But per THIS
Note that the DisplayFormat property does not work in user-defined functions.
So one cannot use UDF to count the colors directly from the sheet. One can use a SUB but it would be easier just to use the same criteria that the custom format uses to count:
=COUNTIF(E2:E30,"Carry Over")
or to count where it is not red:
=COUNTIF(E2:E30,"<>Carry Over")
looking for a conditional formatting trick to do this.
if value of Cell A1 = 1 then cell B1 should be Formatted. If the value of A1 = 2 then Cell B2.
conditional Formatting range should be changed dynamically based on value of cell A1.
This can be easily solved with Conditional Formatting, no need for VBA.
Mark your cells B1+B2, Choose Conditional Formatting (from Home-Tab), New Rule, Select "Use a formula...", enter =$A$1=ROW() as formula and set the Format to whatever you want.
UPDATE (after your comment what you want to format)
If the ranges you wan to format are always the same size and with the same distance, you can use a formula like
=AND(MOD(COLUMN()-1,4)>0,INT((COLUMN()-1)/4)+1=$A$1,ROW()>=5,ROW()<=10)
This checks if the row is between 5 and 10 and divide the column by 4 to check in which "block" you are. The Mod-part prevents the formatting of col A, E...
If the blocks you want to format are more complicated, you could solve this with an UDF:
Public Function calcFormattingVal(r As Range) As Integer
If Not Intersect(Range("B5:D10"), r) Is Nothing Then
calcFormattingVal = 1
ElseIf Not Intersect(Range("F5:H10"), r) Is Nothing Then
calcFormattingVal = 2
Else
calcFormattingVal = -999
End If
End Function
Now, put the following formula as conditional formatting. Be aware that you have to pass the address of upper left cell where your formatting starts as parameter to the function. So if you mark the range "B5:H12", use B5 as parameter.
=calcformattingval(B5)=$A$1
I am trying to set up an if statement formula that will read the color of one cell and place a value in another based on that color. I have tried writing several if statements to do this but cant find one to read the color. The sheet is set up to read a date cell. I have conditional formatting set up to color my weekends. I need a value "200" to show on days that are not on weekends and "0" to show on weekends.
If you were able to do the conditional formatting, you should be able to use a similar formula to input the value. I am guessing it reads the date cell, figures if it is the weekend or not and then inputs the value.
Assuming, for example, the non-weekends are Red (vbRed) then create a UDF (VBA, Add Module and paste the following:
Public Function checkColor(cell)
If cell.Interior.Color = vbRed Then
checkColor = 200
Else
checkColor = 0
End If
End Function
To use the function:
For example to check A1 and put 0 or 200 in B1, in B1 type
=checkColor(A1)
What we are trying to accomplish is to reference text color in conditionally formatted cells that meet a certain metric. We have a for loop that checks the text color of each cell going down a row.
Colored cells done via conditional formatting can't be referenced via font.color as manually/VBA colored cells are (as far as I know), so we are looking for a way to reference the conditionally formatted color/look in the formatting function and grab the color.
Dim rstarpos As Long
Dim cstartpos1 As Long
rstartpos = 9
cstartpos1 = 3
For i = rstartpos To 10
Sheets("Scorecard").Select
Cells(i, cstartpos1).Select
MsgBox Cells(i, cstartpos1).Font.Color
Font.color would ideally report what the font color of the cell in the loop is. However, because of the conditional formatting it's not. Is there a way to call the conditionally formatted cell's color?
Thanks for your help.
If you're using Excel 2010, you can use the DisplayFormat property of a range to get its displayed format, including the effects of conditional formatting (and table styles). In your example, the last line would change to:
MsgBox Cells(i, cstartpos1).DisplayFormat.Font.Color
Hope this helps.