Conditional Format Based on color code - vba

I need to conditional format background color of Columns O:Y based on the color code AF:AK, is there a conditional format formula, or VBA code I can use.
Please ignore current format on columns O:X

You can't set the background colour to match the numbers directly in those cells with conditional formatting, though it is possible using VBA.
However, it is easier to check the value of the cells using the standard Conditional formatting rules and set the colours manually. This means you can have any colour matched to any number. Of course, you can choose the correct colour to fill if this is important to the solution.
I have set this up on a sheet below. I put the conditional formatting formula in the first cell (removing the $ symbol the system puts in for you) and copy across and down.

Related

Border all cell with data, no border all cell without data, using VBA

I have data from cell A4:E2000.
What I want to do is to border the range which containing with data (A4:E2000). However, the range cell containing data is random. So I don't want to use fix range in the code.
Further, the rest of the cell without data is set to no border.
How to do this using VBA?
You can use simpler conditional formatting to achieve this.You will need three conditional formatting rules. Goto Conditional formatting ==>New Rule==>Use formula.
Enter this formulas separately for each condition.
First rule: =AND(A3="",A4<>"") applies to range =$A$4:$E$2000 . under formatting options choose Upper Border.
Second rule: =AND(A5="",A4<>"") applies to range =$A$4:$E$2000. under formatting options choose Bottom Border.
Third rule: =AND(B4="",A4<>"")applies to range =$A$4:$E$2000. under formatting options choose Right Border.
Result is shown below. If you wish to add left border aswell, use same logic as above.

Flexible Data Label Formatting

I'm hoping to add custom data labels to a stacked bar chart in Excel 2010. Each bar will have a label value pulled from a value in the sheet which is not necessarily equal to the height of the bar itself.
The sheet I'm making is a template and has drop-down selections to change the units of the data. For example: $MM with 1 decimal point, K with 2 decimal points, $ with 0 decimal points, etc... I'm running into an issue formatting the labels to match the data formatting selections. I've tried two approaches:
Formatting the data labels themselves using VBA. Partial code below for $K with one decimal:
`With ActiveChart.SeriesCollection(x).Points(y)`
.DataLabel.Text.NumberFormat = "$#,##0.0,"
Unfortunately, the labels don't seem to read the commas and divide by one thousand, so I can't accurate display thousands or millions. A value of 1000 in the above code will display as $1,000.0 instead of the desired $1.0.
Format the values in the worksheet, and then just read them with VBA. Basically, I use conditional formatting to properly display the values on the sheet, and then read them with .DataLabel.Text = Cells(r,c)
Unfortunately, though the data is formatted correctly, the values are unchanged and the labels display with no custom formatting at all.
Is there any reasonable way to achieve my goal? I'm hoping there's a way to either (1) make commas count when changing data label number formats or (2) change the actual values of the data in my sheet based on the formatting drop-down selections (instead of just giving them custom formatting which leaves the value unchanged).
Thank you,
Lance
I think the words "conditional formatting" are your issue here: I've had problems with VBA reading the underlying format of a cell when it's conditionally formatted (admittedly, my issue was with colour, rather than number format, but I expect the reasons for it not working would be the same).
If you adopt your second approach, i.e. relying on the worksheet's format using the chart's "Linked to source" option, then on a trigger of when the drop-down option is changed, you could use VBA to set the format on the worksheet instead of using conditional formatting - then the chart would pick up whatever format you're using.
Please try this:
?Format(1000,"$#,##0.0,")
$1.000,0
?Format(1000,"$#,##0,.0")
$1,0
?Format(1234,"$#,##0,.0")
$1,2

Format One Cell with ColorScale Based on Range of Cell Values

I need to format a single cell with a gradient color based on the values of a range of cells. Similar to the conditional formatting with a ColorScale, except only applying the formatting to a single cell based on the values of a range of cells.
Most likely this will need to be done in VBA. I can't seem to find a simple way to do this without rewriting a similar script to the built-in ColorScale methods.
Example:
B10 formatted with a color in a scale based upon the values of B10:B40. ColorScale would be type 3 with Low, Mid (50%), and High. But I don't want to format any cells other than B10, just use the values of the range B10:B40
I will then do the same for B11:B41, but only formatting B11, then B12:B42, B13:B43, etc..
All I need is to figure out how to create a ColorScale based on a range of values but only apply the formatting to one of the cells.
Edit:
If someone knows a way to create a color scale script similar to the conditional formatting one built into Excel, that would also be a good fix. If I can just calculate the scale from the values in the range of cells and apply to the one cell with the color grade, that would be a solution.
I think what you are after is a 3-color scale for B10 to B40 (so that B10 acquires a colour based on that cell's ranking in the range) together with a separate rule that applies white formatting (in appearance, no formatting) to B11:B40. The latter rule should be at the top of the list of rules and Stop if True checked.

Change #N/A to Blank cell

How can I change the #N/A to the blank cell if nothing in that cell?
Eg. =VLOOKUP(B19:B36;$TABLE.A1:C46;2;0)
I think I might need something like an ISERROR check but I don't 100% know what I'm doing.
If we're talking about Excel 2010 and later you can use IFERROR:
=IFERROR(VLOOKUP(B19:B36;$TABLE.A1:C46;2;0);"")
You can also put text into the final string result
The question was misleading about the spreadsheet software as 2 different spreadsheets were originally stated in tags. However, it can be seen that the question is about OpenOffice Calc:
- Absolute sheet referencing ($ sign before the sheet name) is not possible in Excel.
- We also see a dot between the sheet name and the range, which is again not possible in Excel.
As in OpenOffice Calc you don't have IFERROR function, the only way is to repeat your main function twice in the following form (you can use both, ISNA and ISERROR, but I suggest ISNA as it's more specific and fits your case):
=IF(ISNA(YourFormula);"";YourFormula)
In your case something like:
=IF(ISNA(VLOOKUP(B19;$TABLE.A1:C46;2;0));"";VLOOKUP(B19;$TABLE.A1:C46;2;0))
You may want to make absolute reference to the range where you look for matching values, as I see you want to copy the formula down.
=IF(ISNA(VLOOKUP(B19;$TABLE.$A$1:$C$46;2;0));"";VLOOKUP(B19;$TABLE.$A$1:$C$46;2;0))
Since the cells will contain a formula this is about appearances, so Conditional formatting might suit, say if the cell background is white, for style choose Font > Font Effects > Font color white.
For this, select the relevant range - I have assumed D19:D36 - and Format > Conditional Formatting... and for Condition 1 choose Cell value is and equal to and:
ISNA(D19)

Assigning a background color to a cell, given a condition on another cell

I am trying to create a formula in Microsoft Excel 2010 to accomplish the following algorithm:
If A1=10, then A2 has a background color of red.
I have basic knowledge of if/then statements in Excel, so I have this so far:
=IF(A1=10, x)
...where x would be the formula for changing the background color of the cell. However, after conducting some internet research on the subject, the consensus seems to be that I should instead use conditional formatting to accomplish this task. I have never used conditional formatting and am having trouble understanding how to utilize it so that a condition on one cell would affect another cell.
This is the conditional formatting screen that I am faced with:
So I guess I have two questions:
Is using conditional formatting the best way to accomplish this?
If so, how can I utilize it to assign a background color to a cell, given the truth of a condition on a different cell?
You can do it using conditional formatting, so you're on the right track. One thing I'm assuming here is that you want to format the cell to the right of the cell with the value - is that correct? If so, you actually don't need to use an if formula (though your logic is correct). In that dialog box, make the formula:
=A1=10
And then when you click OK, change the Applies to range by clicking on the little chart icon next to it and clicking cell B1. Then do apply, etc., close out the box and try typing 10 in A1. When you need to expand the range, you can just change that Applies to range to encompass everything you want affected. In the example below, cells B1:B26 will all change if 10 is entered in the cell directly to the left (column A).