I am seeking help with a conditional formatting VBA code.
What I am basically looking for is to review each row starting from row “H2:Y2” and compare it with the “min” (F2) and “max” (G2) cells and highlight them as per the following conditions/colors:
If the value in the cell is between 0 and 50% of the min -> Red
If the value in the cell is between 50% and the min -> Yellow
If the value in the cell is between the min and the max -> Green
If the value in the cell is above the max -> brown
The program should stop once it has reviewed all rows/columns with a value.
Thanks a lot in advance!
Best,
Ugo.
Example without the use of VBA:
Select H2 and create 4 new cond. formatting rules by formula:
=H2>($G2) For brown
=AND(H2<=$G2,H2>=$F2) For green
=AND(H2<$F2,H2>=$F2/2) For yellow
=H2<($F2/2) For red
Then you copy H2, select the entire range that you want to apply the cond. formatting on, right click, and select paste formatting. (Or just edit the range in the managing tab for the conditional formatting)
Done.
The trick is to get the $ right, which sets the reference as absolute. So H2in the formula has no $ so this will change as the formula moves.
The min/max columns have a $ in front of the column name, because we always want to look at that column. But none in front of the row number, as we want to go down the rows and use the min/max for those rows.
Related
I am trying to setup conditional formatting so that the formatting takes effect if the previous 4 cells in a column are blank. I need the range inside the conditional formatting formula to move as it is applied to cells below it, for example:
If I am tracking sales by store, if there is a 4 week period where a certain store doesn't record any sales I want those 4 weeks to automatically highlight.
My current formula is to select cells B5:B11, enter the formula =SUM(B2:B5)=0 to trigger the cell highlighting.
My problem is that when I look at cell B6 the range it looks for to be blank is still B2:B5 and I need it to be B3:B6.
Is there a way to set this up so that the range will change as it moves down a column?
This one has gotten me thinking a bit, and here is my solution for it.
My solution needs to use four conditional formattings, i.e. set up four conditional formattings in each cell, and then use format painter to apply the conditional format to all the cells.
Suppose your week table is in range A1:D20, and suppose you want to highlight cells if there are at least (not only) four consecutive blank cells.
Highlight cell B2, and then set up conditional formatting using the following four formulas:
=SUM(OFFSET($B2,0,0,4,1))=0
=SUM(OFFSET($B2,-1,0,4,1))=0
=SUM(OFFSET($B2,-2,0,4,1))=0
=SUM(OFFSET($B2,-3,0,4,1))=0
Then should have something similar to the following when examing the conditional formatting window:
Lastly, highlight cell B2, use the Format Painter function under Home tab and then apply the format to the rest of the cells in the week table. Then you should have something similar to the following:
It is easy to find the first blank cell of four consecutive blank cells, but it is difficult to identify the second, third and fourth blank cells using one formula. The workaround uses four different formulas to identify each of the four blank cells (I hope this makes sense). Please note the following is only looking at Column B of my example, not all columns:
Not pretty, but it works. This will highlight all occasions where the store has at least 4 weeks of consecutive donuts.
Columns B:D = Original Data
Columns E:G = Helper Set 1
Columns H:J = Helper Set 2
There's probably a way to get just one helper set, but this works and was easy to validate. First I added 3 empty rows above week 1.
In cells E4, E5 and E6 place a 0. You don't have to, you could also leave these blank.
Cell E5 formula, which is counting the number of consecutive blanks:
=IF(ISBLANK(B5),E4+1,0)
Drag it over to column G and drag it down.
Cell H5 formula, which is looking at 4 weeks later to see if there were consecutive blanks found in helper set 1:
=IF(E8>=4,"Yes","No")
Drag it over to column J and drag it down. Also, in the row above it, repeat week 1 values.
Lastly, select your original data range (B5:D14) and create this conditional formatting formula:
=(OR(H5="Yes",H4="Yes",H3="Yes",H2="Yes"))
Once you're satisfied, you can hide rows 2:4 and can also hide your helper columns.
Apply the following condition to each respective ranges:
Range: B2:D2:
=SUM(B2:B5)=0
Range: B3:D3:
=OR(SUM(B2:B5)=0, SUM(B3:B6)=0)
Range: B4:D4:
=OR(SUM(B2:B5)=0, SUM(B3:B6)=0, SUM(B4:B7)=0)
Range: B4:D8:
=OR(SUM(B2:B5)=0, SUM(B3:B6)=0, SUM(B4:B7)=0, SUM(B5:B8)=0)
Result with sample data:
How can I increment the gradient colour to match a value given in a cell.
This is a mock up using cells to show the output I want.
What happens when using gradients that the length of the line shrinks but all the gradient colour stops remain. How can I stop the gradients at the colours based on value.
This is a bar chart with gradients as you can see the line length changes but all colour stops still show.
Apply formulas right next to the question rating and then do conditional formatting as per my screenshot.
The formula is to fill the cells with value 1 or 0 , so if you have 1 in the cell it should be colored otherwise no fill.
Similar one to Imran's solution but with following changes,
A different formula for validation
Use of Excel Tables so that you can add / remove rows and keep the conditional formatting range dynamic
Once you have the initial data set ready please convert the data range including the columns for color fill to an Excel Table (Select the entire range including headers -> press Ctrl + T (OR) Click on 'Insert' Tab in Ribbon -> Under 'Tables' section click on 'Table')
Once you get your data set converted to an excel Table select the column range (here B2: B4) within the table for applying 'RED' fill
Shortcut: Select any cell in the column B within the table and press Ctrl + <Space Key>)
Goto Conditional Formatting -> New Rule -> Use a formula to determine which cells to format
RED =COLUMN(B$2)-COLUMN($B2)+1<=$A2
Click 'OK' and hit 'Apply'
Repeat the same for remaining 4 columns with the below formulas,
ORANGE =COLUMN(C$2)-COLUMN($B2)+1<=$A2
AMBER =COLUMN(D$2)-COLUMN($B2)+1<=$A2
L GREEN =COLUMN(E$2)-COLUMN($B2)+1<=$A2
D GREEN =COLUMN(F$2)-COLUMN($B2)+1<=$A2
Here is the screenshot showing the formula used,
The conditional formatting range will automatically expand / contract when rows are added / deleted.
Cheers !
I have a spreadsheet that has a 7000 rows. My sheet does have a header row. Column G is not supposed to have any cell with a value greater then 1000. I want to highlight red the cells with these "bad values". This I accomplished with the conditional formatting cell value greater then 1000 and applied it to G2:G10000. even though I would love to apply this G:G, so that I don't limit this to just 10,000 rows (there may be rows ith future then the current 7,000).
My bigger issue is that to highlight that column G has a "bad" cell(s) I would lime to highlight all of column G.
I tried using a conditional formatting formula = $G2>1000 and applied it to G:G it only highlighted the cell. I tried = $A2>1000 and applied it to G:G, It highlighted the entire column always even when the condition wasn't met.
What do I do?
You can accomplish this with a COUNTIF formula. I mis-read and did this for a value greater than or equal 10,000. Take out one of my ZEROs in the equation!
As the solution stands, if any cell in column G exceeds (or equals) 10,000, the entire column will highlight.
This is my first post and I've been searching forever but need some help.
I have a spreadsheet that contains Stock Codes in column A for 153 rows (A2:A153) and dates in columns F through BL that list the quantity for each Stock so, for example, it looks like this linked image:
The issue is that there are a ton of rows that have Quantities of just 0, I want to use conditional formatting to highlight ANY row that contains a number greater than 0 in ANY of its columns.
So for example if Row 5 has a 7 in Z5, even if every other column is 0, then the entire row highlights green.
Likewise, if every column for Row 5 (A-BL) is 0 then it doesn't highlighted.
I thought this would be easy but I'm struggling so any help would be appreciated.
Thanks!
Here's what you'll need to do:
Select cell A1
Click "Conditional Formatting" -> "New rule"
"Use a formula to determine which cells to format"
Type the formula =COUNTIF(1:1, ">0")
Choose the formatting you want
Click OK, then go to "Conditional Formatting" -> "Manage Rules"
Change the area your rule applies to so that it fits whatever rows you want (ex 1:1000)
Here's a GIF showing the steps
EDIT: To get the rule to include negative numbers, just change the formula to =OR(COUNTIF(1:1,">0"),COUNTIF(1:1,"<0"))
If you played with multiple rules and tweaked them a bit you could even get the row to highlight red if the average of all numbers in the row is negative and green if it's positive.
Try:
=IF(OR(COUNTIF($A1:$D1,"<0")>0,SUM($A1:$D1)=0),FALSE,TRUE)
I'm wondering how to use conditional formatting in order to highlight specific cells in a column that return an error message in another column after applying a function to it.
eg) Column 1 has data 1 ... n
Column 2 has data f(1) ... f(n); f(n) being a function that sometimes returns errors.
I want to color the cells in Column 1 that return the error in column 2. How would you do this? Thanks!
You can use a simple ISERROR().
Let's say that column 1 is A and column 2 is B.
Select cell A1 and then select the whole column. Cell A1 should be slightly less dark than the other cells (it's the active cell in the selected range). Once you have this, go to conditional formatting and under 'New rule' and 'Use a formula to determine which cells to highight', put the formula:
=ISERROR(B1)
Pick a formatting (e.g. Fill and yellow) and click OK. That should highlight the cells for which column B has errors.