I’m wondering if someone can assist with a conditional formatting issue i just can't wrap my head around
We currently have a table with names in and next to the name a number
Bob 5
Michael 6
Now if i type bob in cell A1 i would like it to highlight that row and the four below it.
another example would be if i type Michael in cell A1 it would highlight that row and 5 below that
any help is appreciated
I couldn't write a simpler formula, but that one worked with the data I tested.
A1 will be where names will be inserted.
The table will range from C1 to D7 (assuming there are no column labels).
Select the table C1 to D7 and insert conditional formatting with formula and use the formula:
=AND(COUNTIF(OFFSET(C1,IF(ROW()-VLOOKUP($A$1,$C$1:$D$7,2,0)<=0,1-ROW(),1-VLOOKUP($A$1,$C$1:$D$7,2,0)),0,VLOOKUP($A$1,$C$1:$D$7,2,0)),$A$1)>0,ROW()>=MATCH($A$1,C:C,0))
And pick the formatting your want.
The formula checks two conditions:
COUNTIF(OFFSET(C1,IF(ROW()-VLOOKUP($A$1,$C$1:$D$7,2,0)<=0,1-ROW(),1-VLOOKUP($A$1,$C$1:$D$7,2,0)),0,VLOOKUP($A$1,$C$1:$D$7,2,0)),$A$1)>0
This checks if there is at least 1 match within a designated range depending of the value in D. It will check if there is a match x rows above the current row where x is the value. If there is, the we get the first boolean value (true or false).
The second ROW()>=MATCH($A$1,C:C,0) ensures that the match is above or on the current row.
Google Spreadsheet Demo
Related
Could you please help me for below formula little bit complicated
Problem is
In a sheet I have three column A,B,C any one column amount if it is same in D column need to highlight and show which column A or B orC..
Example
A B C D amount in each row
4 5 7 4 please highlight bez a and d match
Next example
5 3 6 2 should not highlight show error msg
In above case D is matching same number with AorBorC
Please help me this logic formula
Formula
=If(countif(A1:d4)=1, "duplicate","unique")
working fine but is there any possibility to show which cell column A or B or C ... If duplicate which column need to mention
Much appreciated for this complicated formula am not sure whether it required VBA here
Your question mentions "Highlight", so here's that part of the solution. Select your first 3 columns of data (A1:C6 in my case). Then go to Conditional Formatting in the Home Tab. Create New Rule, using a Formula to determine which cells to format.
Here's the formula:
=A1=$D1
Change the format fill to your color of choice. Click OK.
EDIT - Adding the last piece here...
Lastly, to display which column(s) match column D value, you could use a formula such as this.
Cell E1 Formula:
=CONCAT(IF(A1=D1,"A",""),IF(B1=D1,"B",""),IF(C1=D1,"C",""))
Drag it down.
XLOOKUP unlike VLOOKUP returns a reference to the cell and not just the value of the cell.
With this in mind =XLOOKUP(D2,A2:C2,A2:C2,NA()) will return the value if it exists as well as the reference.
If we wrap the Return Array with the Column function it will return the column number.
=XLOOKUP(D2,A2:C2,COLUMN(A2:C2),NA())
Add the ADDRESS function to return the cell address (this will return the address on row 1)
=XLOOKUP(D2,A2:C2,ADDRESS(1,COLUMN(A2:C2),4),NA())
Now substitute the 1 in the cell address with a blank:
=SUBSTITUTE(XLOOKUP(D2,A2:C2,ADDRESS(1,COLUMN(A2:C2),4),NA()),"1","")
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:
Sheet1
[
Sheet2
[
On Sheet 1 I have four columns Col A= 1st adjustment, Col B= 1st Check, Col C= 2nd Adjustment, Col D= 2nd Check.
The values in these columns are either 0 or non 0. Always a number. For the two adjustment columns I format them to be Red (if they are non-zero) and for the two check columns I format them to be Yellow (if they are non-zero).
On sheet 2 there is a column that pulls and combines the the sets of adjustments and checks and assigns them to the correct employee ID #.
Somehow I need the formatting on the column in sheet 2 to be red if the number came from an adjustment column on the other page and yellow if the number came from a check column on the other page. And no color if it is equal to 0.
What is the best way to do this? I have not been able to find a solution.
The conditional formatting rules I have are all applied to column C Sheet 2. They are:
#1- Cell value equal to = 0 (no fill)
#2 Cell value equal to =Sheet1!$E1 (yellow fill)
#3 Cell value equal to =Sheet1!$C1 (yellow fill)
#4 Cell value equal to =Sheet1!$D1 (red fill)
#5 Cell value equal to =Sheet1!$B1 (red fill)
Assuming that both lists start in A1, put this formula in cell D2 of Sheet2:
=IF(C2=0,0,IF(C2=INDEX(Sheet1!$B$2:$E$7,B2,(A2-1)*2+1),1,2))
Then select the range C2:C13 and open the conditional formatting menu. Add 3 new rules based on formula. The first formula is:
=D2=1
and set the format as filled in red. The second formula is:
=D2=2
and set the format as filled in yellow. The third formula is:
=D2=0
and set the format as unfilled (which is not the same as no format selected). This last rule is not strictly necessary if none is going to change the format of your range manually. Still...
Note that each formula for the conditional formatting is written without any $ that would lock the reference. Therefore each cell in the range $C$2:$C$13 will translate that formula relatively to its own position. Cell C2 will "look into" cell D2, cell C3 will look into cell D3, C4 into D4 and so on. You can of course hide column D and the conditional formatting will still work.
You could also make it without using an extra column. Just edit the formula meant for cell D2 accordingly and use it in your rules. Something like this should work:
=IF(C2=0,0,IF(C2=INDEX(Sheet1!$B$2:$E$7,B2,(A2-1)*2+1),1,2))=1
=IF(C2=0,0,IF(C2=INDEX(Sheet1!$B$2:$E$7,B2,(A2-1)*2+1),1,2))=2
=IF(C2=0,0,IF(C2=INDEX(Sheet1!$B$2:$E$7,B2,(A2-1)*2+1),1,2))=0
Formula details (as asked in comments)
B2 is for the row. In the context of the INDEX function it says at what row of the range ($B$2:$E$7 in the formula we see here) the INDEX function has to "look". If B2 is 1, it will consider the first row of the range (in our case row 2). If it's 2, it will consider the second row (in our case row 3).
(A2-1)*2+1 stands for the column. In the context of the INDEX function it says at what column of the range ($B$2:$E$7 in the formula we see here) the INDEX function has to "look". If the result is 1, it will consider the first column of the range (in our case the B column). If it's 2, it will consider the second column (in our case the C column).
About (A2-1)*2+1: let's change it a bit so it will be easier to visualize while i explain it:
1+(A2-1)*2
We can divide the formula in 2 parts: the 1 which stand as our starting point (the first column) and the (A2-1)*2+1 which deal with the shift in columns according to the shift in weeks. In cell A2 we find the number of the week. In the first sheet we have 2 columns for each weeks. Therefore when the week shifts by 1, our target column will have to shift by 2. We can't just multiply by 2 the week sheet because it's the shift from the first week that counts for 2, not the actual value. At the first week we will have no shift. Therefore our shift will have to be 0; but we can't just use a 0 because there is no "zero column" in a range. Therefore we need to have our starting value of 1 that is summed to the shift. This way for the first week we will have:
1+(1-1)*2
1+(0)*2
1+0
1
First column of the range $B$2:$E$7 (which is column B). For the second week we will have:
1+(2-1)*2
1+(1)*2
1+2
3
Third column of the range $B$2:$E$7 (which is column D).
Over all the formula IF(C2=INDEX(Sheet1!$B$2:$E$7,B2,(A2-1)*2+1),1,2) basically checks if the value in C2 is the same as the first column of the given week. If it's the same value it returns 1, otherwise it returns 2 (basically assuming that the value will be equal to the one in second colum of the given week).
Report any question you have or bug you have encountered. If, according to your judgment, this answer (or any other) is the best solution to your problem you have the privilege to accept it (link).
Let me give you a general approach for conditional formatting, based on a formula:
First you try to set up your formula, which you enter in some cell. The result of the formula should be TRUE in case you want the formatting to be applied, and FALSE in all other cases.
Please edit your question again, showing the formula you have tried for configuring this.
Oh, you just want to copy the formatting of that first sheet. But tell me, how is the formatting of that first sheet determined? Is it also the result of a conditional formatting? And about the numbers of the ADJ/Check column, is that just the sum of the values in the first sheet?
My question is, how to set the row value dynamically in a conditional formatting formula, i.e.
=D$1=0
where the 1 has to be replaced dynamically with a value hold in a specific cell (first column = $A and related row = 8)
Example: Assume a number of employees with a distinct ID, a range of cells to be conditionally formatted according to true or false entries in another range associated to the employees IDs. The column part of the reference in the written formula is fix (the column to be formatted). The row value is fix too. The employees name depends on the ID and inserted by VLOOKUP. Each field in the to be formatted range is representing a task to do. When I now have to assign a task to a different employee I can simple change the ID in front of the name and via VLOOKUP a new employees name will appear. Unfortunately the conditional formatting has to be customized in addition because the row number is not dynamic. 5 Employees means I have 5 conditional formatting formulas.
What I want is: Only one conditional formula
D8 has to be yellow when D1 is '0' (ID is 1 = Alex). I now change A8 to ID 5 = Mark. D8 has to change to white because D5 is '1' The ID has to be the row part of the formula.
The column part is fix 'D' but the row part has to be the number of the ID dynamically.
Sample excel screenshot:
How to solve this problem? Hope the question is not only confusing and maybe helps to build more flexible excel sheets.
You could try using an INDEX formula for this purpose:
=INDEX($D$1:$H$5,MATCH($A8,$C$1:$C$5,0),COLUMN()-3)=0
I think I solved the problem, never found it without the index hint from maxhob17.
=INDEX(D$1:D$5;$A8)=0 as the formatting formula placed in cell D8
That means search matrix D1 to D5 in row given through ID in A8
=$D$8:$H$12 that formula will be applied to that area
The rest is done by excel itself. Be aware of relative and absolute cell
references
Trying to create a Gantt chart look in Excel. I have two columns, A and B (A = start date, B = End Date).
Across the top of the page (Row 2) I have a column with a date for every date of the project (custom formatted with "d" for readability, with the name of the month in Row 1.)
I'm now trying to apply conditional formatting rules to turn the cell in the column a specific colour (say, green) if:
the value in A[this row] is greater-than-or-equal-to [this column]2.
and
the value in B[this row] less-than-or-equal-to [this column]2.
I've dug through a few answers recommending ADDRESS() and INDIRECT(), but I'm stumped on getting this to work. Any thoughts?
You can use AND to combine the conditions. I'm assuming the 'Gantt chart' starts as from column C and the active row is 2 here.
Select C2 and the rest of the row (to 31, 30 or 28/29 depending on the number of days in the month).
Pull up conditional formatting with formula and put:
=AND(C2>=$A2,C2<=$B2)
Pick the format fill green and that should do it
In conditional formatting if you use the first cell of your selection in the formula it automatically turns that into a relative formula.
For example if you use the formula: =A1>5 and select cells A1:B5 it will check each cell to see if its >5 not just cell A1 (so it automatically increments the row and the column for you). Usually this is preferred over using indirect but sometimes indirect is necessary.
So using indirect you can utilize the row() and column() functions. So in your example:
the value in A[this row] is greater-than-or-equal-to [this column]2.
and
the value in B[this row] less-than-or-equal-to [this column]2.
Would look like:
=AND(INDIRECT("A"&ROW()) >= INDIRECT(CHAR(COLUMN()+64)&"2"), INDIRECT("B"&ROW()) <= INDIRECT(CHAR(COLUMN()+64)&"2"))
Hopefully that helps
It works for me without ADDRESS or INDIRECT. This is the formula inside the conditional formatting. If I have to guess what's going on, it's most likely that you are not placing the proper anchors ($).
=AND(C$2>=$A3,C$2<=$B3)