Conditional format first non-blank cell in multiple rows - excel

Hopefully this will stop the chain.
See the linked questions if you want more background, but I need to conditional format multiple rows (2,000+) from the FIRST (leftmost) non-blank cell + the next 11 columns after it. Not sure if it's needed for the conditional format formula, but I am able to get the start cell for each row, can kind of get the end cell (see below).
Cell address of the first populated cell in the row (*the data starts on row 2, the values begin in column C and end in column P):
{=(ADDRESS(2,COLUMN(INDEX(C2:P2,MATCH(1,IF(C2:P2<>0,IF(C2:P2<>"",1)),0)))))}
^ this gets me an absoluted text-version of the leftmost populated cell in each row. I have all these addresses in a helper column. I am then able to get the desired stopping-point for the format (12th cell to the right of the cell returned from above formula), but I have to manually enter the cell address derived from above formula:
=ADDRESS(2,COLUMN(OFFSET(N2,0,11,1,1)))
I can't nest the start cell formula inside this second formula or it breaks.
THANK YOU!
Desired result (ignore the different colors, they can be the same):

I added a helper column C that finds the first non blank in the row (my data went from column D to column AZ)
=MATCH(TRUE,INDEX((D2:AZ2<>0),0),0)
My conditional format rule applied to D2 to AZ4 was to highlight when the following was true:
==AND(COLUMN(D2)<($C2+11+COLUMN($D2)),COLUMN(D2)>=$C2+COLUMN($C2))
You can modify this to put the helper column where you wish, and to use named ranges.
(Had to add condition to not start coloring before the first instance!)

Related

Conditional Formatting Based On Multiple Columns

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?

Check if text exist in rest of Column, and if so, use info from that row it is in

I'm after a way to a cell to check another cell that I'm inputting text into, and for it to see if that text value is the same anywhere else in the column, and if so, it grabs the number value which is in the same column as itself but in the row of the text that checked for.
So if you use picture, you can see I've currently got E7 selected. I'm wanting it to check the "GOLF COURSE" column for any other row that contains the same text it has in it's own row. For this it's "Course1". I'd like it to check through the rest of column B if there are any matches for "Course1" which there is in B3. If it matches I'm wanting it to then use the value that's in same column as it (E) but the same row as the matched text in column B. In this case I would want it to copy the value that is in E3.
If there wasn't a match (as it's a new course lets say) then I need to be able to just click on the cell and input the numbers needed, which I would be able to do anyway but just throwing it in for sake of info.
I've tried all sorts of googling and thinking how I could possibly do it but it's too difficult for my amateur knowledge of Excel.
I believe you are looking for INDEX/MATCH:
=IF(COUNTIF($B:$B,$B7)>1,INDEX(E:E,MATCH($B7,$B:$B,0)),"New")
I added a COUNTIF check to ensure that the same course exists more than once in column B, without it, you would be getting a circular reference formula (which would also happen with the above formula if the same course appears more than once, but you use this formula on the first occurrence of that course, so make sure do not use it the first time you fill out the PAR scores for a particular course).
Merged Cells Messing With INDEX/MATCH
The Formula
Copy the following formula into cell E7:
=IF(AND($B7<>"",$D7="Par"),IF(ISERROR(MATCH($B7,$B$3:$B5,0)),"Par",INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0))),IF(AND($B6<>"",$D7="Strokes"),IF(ISERROR(MATCH($B6,$B$3:$B4,0)),"Strokes",INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1)),""))
Image
How
We are creating the formula in cell E7.
MATCH
Syntax: MATCH(lookup_value,lookup_array,match_type)
We will use MATCH to find the position of COURSE1 in the above
cells of column B.
The 1st argument is lookup_value which will be the cell in the same
row of our row (7) in column B: B7 where we will lock only the
column (we will not be searching in other columns): $B7.
The 2nd argument lookup_array will be a range. The first cell will be
cell B3 whose row and column we'll lock, because we will always
start the search from this cell in every other cell to the left or
below: $B$3. The last cell will be B5 where we will lock only the
column: $B5.
And finally we will use 0 as the parameter of the 3rd argument
match_type to find an exact match.
Now were ready to write our MATCH formula:
=MATCH($B7,$B$3:$B5,0)
Which will return 1 i.e. an exact (0) match of B7 was found
in the 1st cell of range B3:B5.
We don't want 1 (E3), but the value in the cell (5).
INDEX
The INDEX function has 2 syntaxes where we will use the 2nd:
Syntax 2: INDEX(reference,row_num,column_num,area_num)
Since were using a one-column range we can safely omit the arguments row_num and column_num, which leaves us with:
Modified Syntax: INDEX(reference,area_num)
The INDEX function used this way will return the area_num-th value
of reference i.e. in our case if area_num is 1 it will return the
1st value in our column range, if it is 2, then the 2nd, etc.
The 1st argument reference will be the same sized range of our
MATCH range in column E: $E$3:$E5 where we will remove the
column locks because we also want to return results for other
columns: E$3:E5.
The 2nd argument area_num will be our MATCH formula.
Our current formula looks like this:
=INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0))
which will return the value of cell E3: 5.
Final Adjustments: IF, AND and ISERROR
That would have been almost (Error Checking) all if the cells in column B weren't merged. Therefore we have to use IF to determine if the row in which we're writing the formula contains either Par or Strokes and adjust our so far created formula for both conditions:
=IF($D7="Par",INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0))
=IF($D7="Strokes",INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1)
=IF($D7="Par",INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0)),$D7="Strokes",INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1))
and (3rd condition) check in column B if there is a value in the row where we're creating the formula for a row containing Par, or the row above for a row containing Strokes, using AND:
=IF(AND($B7<>"",$D7="Par"),INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0)),IF(AND($B6<>"",$D7="Strokes"),INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1),""))
Finally we have to add some error checking, because if the match was not found the formula will produce and #N/A error:
=IF(AND($B7<>"",$D7="Par"),IF(ISERROR(MATCH($B7,$B$3:$B5,0)),"Par",INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0))),IF(AND($B6<>"",$D7="Strokes"),IF(ISERROR(MATCH($B6,$B$3:$B4,0)),"Strokes",INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1)),""))
Now we are ready to copy the formula to the right and below as far as we need.

excel conditional formatting reference depending on cell-value

I have two sheets on my xls-document. I want to add conditional formatting to my second sheet. The conditional formatting should be depending on the frist sheet. But there is no fix cell i can reference. The cell which should be referenced in my formular should depend on a value which can be entered by the user.
First sheet:
The row A functions like an index. The rows D, E and F could be filled with anything. But they can also be empty.
Second sheet:
The row A tells me ony which row from the first sheet my conditional formatting should refer. The rows B, C and D should be formatted like this:
If the column D with the index 1 of my first sheet has a value, all rows on my second sheet with the index 1 should color red if the column A is empty. If the column D with the index 1 of my first shett has no value, all rows on my second sheet with the index 1 should color red if the column A is not empty.
I know how to reference cells from another sheet and how to color the cell red. But i dont know how to make it depend on the index (column A).
VB is not allowed. Only conditional formatting. Can you guys help me?
I was able to solve my problem with the VLOOKUP-function.
VLOOKUP(A4;Firstsheet!$A$4:$F$14704;4;FALSE)
This looksup the given area on my first sheet (second parameter) and searches for the index (first parameter). When the index is found, it returns the fourth column of the found row (thrid parameter). I dont know what the fourth parameter does.
This just returns the value from the indexed cell from my first sheet. I was able to use this to solve my problem.
Her is the whole formular for Secondsheet.B4:
=AND(NOT(ISEMPTY(A4));OR(AND(NOT(ISEMPTY(B4));ISEMPTY(VLOOKUP(A4;Firstsheet!$A$4:$F$14704;4;FALSE)));AND(ISEMPTY(B4);NOT(ISEMPTY(VLOOKUP(A4;Firstsheet!$A$4:$F$14704;4;FALSE))))))

How to refer to multiple adjacent cells

I have a work sheet in which there are several cells with a specific entry - let's say "A". These are not all in the same rows/columns. After each cell is a date.
I need to count the number of cells containing "A" which also have a specific date in the cell immediately to its right. I've tried combinations of Countifs and Indirect, with no success. How can I achieve this?
This counts the number of times that there is A in column A and 1 in column B
=SUMPRODUCT(($A$1:$A$5="A")*($B$1:$B$5=1))
This outputs in cell D1
Not too difficult.
I have created a sample sheet with 8 rows and 5 columns of data.
See below, the formula in cell C12 counts the number of occurrences where the a cell with a date of October 31, 2017 is directly to the right of a cell that contains the text A.
If you want more info as to how this works, read on:
When searching for cells that contain A, you don't search in the last column of the data (in this case, column E) because it is impossible for a column to the right to have any date in it. This is why a portion of the formula says A1:D8="A" instead of A1:E8="A". This is the same reasoning why we start searching for a date in column B rather than column A in the formula.
You can achieve this with a helper row. Add additional row on top of your Worksheet. In cell "A1" enter formula below.
=COUNTIFS(A2:A2000,"A",B2:B2000,"YourDate")
Drag this formula to the rightmost of where you have data, then simply sum all values returned by formula.

populate Excel Formulas in the an entire column after changing some of the formula values

I have two excel sheets. The one that contains the data "gdsc_en_input_w2" and the other one will contain a selective number of cells from "gdsc_en_input_w2".
I am using the current formula:
=INDEX(gdsc_en_input_w2!$A$1:$YE$13848,MATCH("AKT2",gdsc_en_input_w2!$A$1:$A$13848,0),MATCH($A$3,gdsc_en_input_w2!$A$1:$YE$1,0))
I want to fill an entire column in the second sheet by referencing columns in the "gdsc_en_input_w2" sheet but based on the values stored in the column $A$1:$A$13848. As you can see the second match() matches only $A$3 ...is there a way to fill the required column with the formula with incremental column reference in the second match() function in the formula above. in other words I want to fill in the second cell of the target column the following formula :
=INDEX(gdsc_en_input_w2!$A$1:$YE$13848,MATCH("AKT2",gdsc_en_input_w2!$A$1:$A$13848,0),MATCH($A$4,gdsc_en_input_w2!$A$1:$YE$1,0))
note that the match now has $A$4 instead of $A$3.
Assuming that I am understanding what you are wanting, this formula is going to be in one column where each subsequent row will have a higher number (3,4,5,...) If that is the case, unlock your formula to read:
=INDEX(gdsc_en_input_w2!$A$1:$YE$13848,MATCH("AKT2",gdsc_en_input_w2!$A$1:$A$13848,0),MATCH($A3,gdsc_en_input_w2!$A$1:$YE$1,0)) (I removed the $ in-front of the 3)
Paste that into the whatever your starting cell is, then auto-fill

Resources