Xlsx Writer Critera If Blank - python-3.x

Given this format:
format0 = workbook.add_format({'bg_color': 'none'})
I'd like to apply it (no background color) if the cell is blank.
Here's what I've tried so far:
worksheet.conditional_format('B2:B14',
{'type':'cell',
'criteria': '=isblank()=True',
'format': format0
})
But I keep getting this error:
KeyError: 'value'
I'm pretty sure I'm not using a correct entry for 'criteria', but I'm not sure how to do it.
Thanks in advance!

One solution:
It appears that setting the color to 'none' produces blue cells, for some reason. So instead, I opted to color blank cells white:
format0 = workbook.add_format({'bg_color': 'white'})
Then, by reading the documentation (what a great idea!):
worksheet.conditional_format('B2:B14', {'type':'blanks', 'format': format0})
I put this before other conditional formats for the same column.

The border of the blank cells are not visible if you use white background color as given in the answer above.It can be modified to
format0 = workbook.add_format({'bg_color':'white','border':1,'border_color':'#D5DBDB'})to give a border to the blank cells that looks similar to default excel cells.

Related

Want to create a chronological row # then reset based on font color

I want to create a column that numbers itself chronologically based on the column to its left based on font color. Then when a new font color appears in the column, I would like it to reset and then number the rows again. Pretty much create a line item column.
I found a code that kind of worked but it wasn't what I needed.
I tried other codes but nothing I found worked.
You could use this function to test the font color:
Option Explicit
Function TextColour(RG As Range)
Application.Volatile
TextColour = RG.Font.Color
End Function
Then use it like this:
Example:

In excel, what is the code to apply colors to a cell based on text in another cell?

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.

Excel return Cell Style in a fromula

In Excel how do I return the Style name applied to a cell as a formula?
When i use the =CELL("Color",AA11) (see below) it doesn't return a colour value, it still thinks it is unformatted, none of the other =Cell() functions seem to return style info either.
These are the styles as given by excel, I've marked a bunch of fields as good, bad or neutral. Ideally I'd like to be able to return 'Good' or 'Bad' etc into a cell.
Thanks
Here is a very easy UDF:
Function GetStyle(rng As Range)
GetStyle = rng.Style
End Function
Call in your cell B2 like =GetStyle(B2)
Edit
It's good to realize a UDF wont recalculate when you are changing the format of a cell!

Excel 2010: Conditional Format Class Schedule based on Subject name

Excel 2010, creating a class schedule. Colour coded per class name.
I have a table, broken in to 10 min amounts.
7 wide, 30 down.
I want to conditionally format all cells that contain the letters ENG in green, all SCI in yellow & so on.
Currently my table colours end up with the top priority cell, rather than end up with a multi-coloured table.
In conditional formatting:
=$R$12="ENG"
=$R$11:$V$20,$R$25:$V$29,$R$34:$V$38 colour = Green
=$R$17="SCI"
=$R$11:$V$20,$R$25:$V$29,$R$34:$V$38 colour = Purple
I either get 'green' or 'purple', I don't get a table with both colours in their respective cells.
R12 = Green
R17 = Purple
U12 = Cyan (eventually) etc etc
I know I'm missing something, I don't know what though.
Thank you
Use relative references in your conditional formulas:
If the highlighted cell in your currently selected range is R12, edit the formula (with mouse and Backspace/Delete buttons, do not press arrow keys when editing the formula) to:
=R12="ENG"
...
(see also Excel vocabulary to find solutions faster for a little more background)
Also you don't have to use a formula for this use case, just choose an option Format only cells that contain > change bettween drop box to equal to > write ENG to the text box.

Reference text color in conditionall formatted cells

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.

Resources