I have an issue in Excel where conditional formatting produces different results if a subset of the characters in the cell have a different colour, depending on whether
the colour was applied with manual editing or using VBA
if applied with VBA, whether the range of coloured characters includes the first character in the cell
I am using Excel in Office 365 on Windows 10, both fully updated as of today.
In the screenshot below cells A1:A6 have the conditional formatting rule
=NOT(ISBLANK(B1))
In cells A2 and A3 I set first three characters to red by editing manually. In A3 the first three characters remain red when conditional formatting is triggered.
In cell A4 I set the first three characters to red text using the macro
Sub RedFirst()
ActiveCell.Characters(1, 3).Font.Color = vbRed
End Sub
Instead of getting the same result as A3 when conditional formatting is triggered, the first three characters turn green (the conditional format) instead of remaining red, and the rest of the text remains black instead of being green, although all the text is underlined from the conditional formatting.
In cell A5 I set the second and third characters to red text using the macro
Sub RedNext()
ActiveCell.Characters(2, 2).Font.Color = vbRed
End Sub
Now, the characters whose colour was set with the macro remain red when conditional formatting is triggered, the same as when I change the text colour manually.
Cell A6 shows the result of conditional formatting without having applied a different colour to any text.
I think A3 and A4 should look the same and changing the text colour manually or using VBA shouldn't make a difference. I have tried different approaches for changing the text colour of the first n characters with VBA but always get the same (odd) result.
Is there a way to set the colour of the first n characters with VBA without getting the odd conditional formatting result? Or is this really how it should work? To me it looks like a program bug that needs to be fixed.
Related
I have an issue with Excel 2013. The conditional formatting just will not work. I've got a VLOOKUP which pulls data from another worksheet. Then I want to use conditional formatting on that data. The conditions are =$N$3>30 to color the cell red and =$N$3<30 to color the cell green. It just stays permanently red or permanently green. I've tried every solution and possible work around I can think of and nothing works.
Does any one have any suggestions?
enter image description here
Value in your N3 (or in column N), is a text thus color is red. Add double dash (--) to your VLookup function to convert the result to number. Your formula should be =IFERROR(--VLOOKUP(A3,... (complete the formula).
I am working on an Excel sheet for the company that I work for and I am having trouble figuring out a specific task within Conditional Formatting.
So I have a rule:
=IF(ISBLANK(B5)=FALSE,IF(COUNTIF('Hidden
Sheet'!$C$5:$C$10,"*"&B5&"*")>0,TRUE,FALSE),FALSE)
That takes the selection in the drop-down of cell b5 and dictates if this specific cell that I have the conditional format in (N5) should be filled with the color red or not.
That works perfectly fine, but when I type in cell N5 it stays red, when I don't want it to. How can I change the fill back to regular after I input something into the cell?
I can provide additional information upon request.
Try changing the CFR formula to,
=AND(ISBLANK(N5), NOT(ISBLANK(B5)), COUNTIF('Hidden Sheet'!$C$5:$C$10, "*"&B5&"*")>0)
We are trying to use cell coloring in excel.
We would like that if a cell color is red it will give a numeric answer in another cell. For e.g. if cell A2 is red then in cell B2 it will be 8.
Does anyone knows how to do it without using VBA?
There is no Excel worksheet function that can evaluate the colour of another cell.
Even if you invent a function and wing the syntax, it will not work.
The Cell() function has a "color" argument, but that does not identify the color. It returns 1 if the cell is formatted in color for negative values; otherwise returns 0 (zero).
https://support.office.com/en-us/article/cell-function-51bd39a5-f338-4dbe-a33f-955d67c2b2cf?NS=EXCEL&Version=16&SysLcid=1033&UiLcid=1033&AppVer=ZXL160&HelpId=xlmain11.chm60173&ui=en-US&rs=en-US&ad=US
So, what you want to achieve cannot be done without VBA.
You may want to shift your paradigm.
Instead of manually coloring a cell, use conditional formatting. The logic that is applied to arrive at the conditional format can be re-used to produce values in other cells of the spreadsheet.
I have used one formula to change the font colour if a cell contains the text "complete" & another formula to add a light blue fill to the entire row if the word "odd" appears in a cell which is in a different column to the first formula.
The conditions seem to clash & although I have changed and played with the order of the conditions & checked there is no conflict in the fill/background or the font colour, even when changing the font colour manually again the fill from the second formula returns the font the cell to black although it is set to automatic in the conditional formatting rule with the fill ?
I wonder where i am going wrong as everything suggests the two conditions should work fine together though when the fill is applied the font goes back to black when it should be green ?
Have you any suggestions ?
I found the issue, I needed to press clear on the font section of the formatting on the fill condition and then clear on the fill. Basically as a rule I press clear on anything not required in that condition and this seems to avoid the conflict and run upto 6 rules on the same cell with no problems!
You can combine multiple conditional formats overlapping cells/rows. (Excel's just a little picky that you do it just right!)
Always use New Rule as opposed to using the built-in rules.
Choose Use a formula to determine which cells to format.
For your example question, I populated the cells as shown above. Select cell B4 and set the conditional formatting as above =($B4="complete") . Note that I removed a $ (dynamic vs absolute cell reference) that was automatically filled in, so that I can fill the formatting's formula down.
Highlight entire Row 4 and set the conditional formatting as below. Again, note the modified $.
When it's working properly, copy entire Row 4, select the rows to which the formatting should be applied, and Paste Formatting.
[
Obviously the steps will vary for you depending on your data and what's in the neighboring cells whose formats you may or may not want affected by the formatting and copy/pasting.
Let me know if that works for you.
From my experience with conditional formatting, I believe that it applies a format to the entire cell rather than individually modifying fill or font colour, so formats will not combine. I had a similar situation and solved it by creating an additional rule. In your case, one that applies your desired font colour and background fill to the 'complete' cell if the same row also contains 'odd' using the AND() function.
I am trying to find a way to change the color of text after applying custom format in excel.
Lets suppose the value in my column are 2,3 and 1
and if I customize this cell by following formula
[<=1]0.0 "year";[>1]0.0 "years"
Now the cell will looks like
Now I wanted to change the color of "Year"/"years" word only to some red color, but not getting any way.
Search a lot and got only a way to change the font-color of full cell by some other color using this.
[Red][<=1]0.0 "year";[Red][>1]0.0 "years"
Please help to achieve this.
Note : I don't want to use VBA for this.
Range.NumberFormat property (Excel) changes the appearance of the values in the cells, without changing the actual values. It can be used to change the color of an entire section of the Number format code(i.e. positive numbers, negative numbers, zeros and text) as this code format does:
[Blue] #.0 "Positive";[Red] #.0 "Negative";[Green] - "Zero ";[Magenta]# "Text"
However, it cannot change partially the color of a section.
Note that cells [B7] and [D7] have a SUM formula to add the ranges [B3:B6] and [D3:D6] respectively.
Using VBA:
Range.Characters property (Excel) can be used to change the appearance of the Characters of the text contents of a cell, as this code does for the range [B3:B6]:
Sub Characters_FontColor()
Dim Cll As Range, b As Byte
For Each Cll In ThisWorkbook.Sheets("TEST").Range("B3:B6")
With Cll
For b = 1 To Len(.Value)
.Characters(b, 1).Font.ColorIndex = 2 + b
Next: End With: Next
End Sub
Note that in the case of the cells in [B3:B5] the procedure changed the font color of the cell instead of each Character like in cell [B6], and that’s because the contents of the those cells are not text.
Regarding Op’s requirements:
I am trying to find a way to change the color of text after applying custom format in excel.
The color of text in a custom format can be changed for an entire section.
Now I wanted to change the color of "Year"/"years" word only to some red color, but not getting any way.
The color of text in a custom format cannot be partially changed within a section.
Search a lot and got only a way to change the font-color of full cell by some other color using this.
That custom format did not change the font color of the cell, it only changed the appearance of the sections within the custom format. To test this, check the font color of the cell and you'll see that it remains as Automatic or whatever it was before applying the custom formatting.
I don't want to use VBA for this.
This cannot be done with VBA. As mentioned before the custom format only changes the appearance of the cell, the value of the cell remains as entered, this allows the use of the cells.value in formulas. The use of Characters in VBA allows change the color of part of the text, but in order to use this the cells.value must be a text string, but then the sum of the cells would be zero. To test this apply the procedure Characters_FontColor to the range [D3:D6] and you'll see no change.
I don't think you will be able to do it from the user interface. However, from the VBA it can be done:
http://vbadud.wordpress.com/2007/11/03/excel-vba-change-font-color-for-part-of-text/