Conditional formatting on a spilled range - excel
(* This might be a duplicated question, but it would be surprising if we don't have this feature yet. *)
I have a table Table5 in Column C, whose height may change. in Column E, I have a formula to e.g., extract unique values, thus the resulting spilled range has a dynamic height.
I would like to make a conditional formatting over the resulting spilled range, for instance, highlight the value which is greater than 5.
But I didn't find how to define a conditional formatting rule over a spilled range (e.g., by using #). I don't want to apply the conditional formatting rule over the whole column.
Does anyone know how to achieve this?
The only way I could think of was:
=AND(ROW($E1)>=4,ROW($E1)<=COUNTA(UNIQUE(INDIRECT("Table5[Coefficient]")))+4,$E1>5)
Use the above formula as a conditional formatting rule on the whole of column E:E.
You could set a conditional formatting rule over the whole column, but use some additional logic to ensure it only applies to the range you want, ie:
=AND(ROW(E1)>=4, ROW(E1)<=4+COUNT(UNIQUE(INDIRECT("Table5[Coefficient]"))), [your condition here])
Apply the rule to E:E and it will only evaluate to True for rows in the range you want.
Update
The Indirect reference can use the spill range, so you could use:
=AND(ROW(E1)>=4, ROW(E1)<=4+COUNT(INDIRECT("E4#")), [your condition here])
Note that Unique is no longer needed. Also, this assumes the values in your table are only numbers.
An alternate workaround is to use a named range which will accept the spill range # assignation.
Assign Named Range "CF_1" as:
=OFFSET($E$4,0,0,COUNTA($E$4#))
The conditional formatting to be applied to E:E can then be:
=AND(ROW(E1)=MEDIAN(ROW(E1),MIN(ROW(CF_1)),MAX(ROW(CF_1))),E1>5)
In essence, this isn't too much different to the answers by JvdV and Professor Pantsless as it kind of boils down to the same thing, but it does have the bonus that it will only apply to only the rows of the spill range (the cells E1-E3 haven't been taken into account yet for the other answers to date).
UPDATE
And in fact, you don't have to use a named range at all as this code will also accept # (still can't work out how to apply over only the spill range though)
=AND(ROW(E1)=MEDIAN(ROW(E1),MIN(ROW(E$4#)),MAX(ROW(E$4#))),E1>5)
I've been using several different conditional formats applied to the entire column, or group of columns. The table looks like this:
The following formulas are conditional formatting applied to the entire row/rows, not individual cells:
Header:
=AND(OR(ISERR(OFFSET(A1,-1,0)),ISBLANK(OFFSET(A1,-1,0)))=TRUE,ISBLANK(A1)=FALSE)
Band:
=AND(CELL("row",A1)=EVEN(CELL("row",A1)),ISBLANK(A1)=FALSE)
Last row (or total row):
=AND(ISBLANK(A1)=FALSE,ISBLANK(A2)=TRUE)
With the following formatting:
If you do not want this formatting to be applied to non-spill cells, you can determine if a cell was spilled or directly input. You can do this with a formula or write a UDF.
Using a formula you need to fake it. You can use ISFORMULA to find where the spill formula was entered, and NOT(ISBLANK()) to identify spilled rows. You would then have to assume a formula followed by non-blank, non-formula cells is a spilled formula. Helper columns may be helpful.
Using a UDF, you can directly determine if a cell is spilled. Below is a basic example. You can add more checking to determine if the formula is actually spilled if desired.
Public Function isFormulaOrSpill(ByVal rRange As Range) As Boolean
Dim this_bIsSpill As Boolean
Dim this_bIsFormula As Boolean
this_bIsSpill = rRange.HasSpill
this_bIsFormula = rRange.HasFormula
isFormulaOrSpill = (this_bIsSpill Or this_bIsFormula)
End Function
Recently I've been building entire tables as spilled ranges (including header and total rows). Here is an example of those who want to give it a shot:
=LET(
Column_Key, Table_Status[System],
Column_FtEstimated, Table_Status[Estimated],
Column_FtModeled, IF(Table_Status[Modeled]>Table_Status[Estimated],Table_Status[Estimated],Table_Status[Modeled]),
Categories, SORT(UNIQUE(Column_Key)),
Array_BoolKey, (TRANSPOSE(Column_Key)=Categories)+0,
Mask1, TRANSPOSE(ISNUMBER(XMATCH(Column_Filter1,List_Filter1))),
Mask2, TRANSPOSE(ISNUMBER(XMATCH(Column_Filter2,List_Filter2))),
Array_BoolMasked, Array_BoolKey,
Masked_FtModeled, IFERROR(Array_BoolMasked*TRANSPOSE(Column_FtModeled),0),
Masked_FtEstimated, IFERROR(Array_BoolMasked*TRANSPOSE(Column_FtEstimated),0),
Array_Ones, SEQUENCE(COLUMNS(Array_BoolMasked),1,1,0),
Body_Count_Lines, MMULT(Array_BoolKey, Array_Ones),
Body_Sum_FtModeled, MMULT(Masked_FtModeled, Array_Ones),
Body_Sum_FtEstimated, MMULT(Masked_FtEstimated, Array_Ones),
Body_Percent_FtModeled, IFERROR(Body_Sum_FtModeled/Body_Sum_FtEstimated,"-"),
Total_Count_Lines, IFERROR(SUM(Body_Count_Lines),"-"),
Total_Sum_FtModeled, IFERROR(SUM(Body_Sum_FtModeled),"-"),
Total_Sum_FtEstimated, IFERROR(SUM(Body_Sum_FtEstimated),"-"),
Total_Percent_FtModeled, IFERROR(Total_Sum_FtModeled/Total_Sum_FtEstimated,"-"),
Array_Seq, {1,2,3,4,5},
Array_Header, CHOOSE( Array_Seq, "System", "Lines", "Modeled Feet", "Estimated Feet", "Percent Modeled"),
Array_Body, CHOOSE( Array_Seq, Categories, Body_Count_Lines, Body_Sum_FtModeled, Body_Sum_FtEstimated, Body_Percent_FtModeled),
Array_Total, CHOOSE( Array_Seq, "Total", Total_Count_Lines, Total_Sum_FtModeled, Total_Sum_FtEstimated, Total_Percent_FtModeled),
Range1,Array_Header,
Range2,Array_Body,
Range3,Array_Total,
Rows1,ROWS(Range1), Rows2,ROWS(Range2), Rows3,ROWS(Range3), Cols1,COLUMNS(Range1),
RowIndex, SEQUENCE(Rows1 + Rows2 + Rows3), ColIndex,SEQUENCE(1, Cols1),
RangeTable,IF(
RowIndex<=Rows1,
INDEX(Range1,RowIndex,ColIndex),
IF(RowIndex<=Rows1+Rows2,
INDEX(Range2,RowIndex-Rows1,ColIndex),
INDEX(Range3,RowIndex-Rows1-Rows2,ColIndex)
)),
Return, RangeTable,
Return
)
Related
conditional formatting of a cell when a cell name is used on a formula inside that cell
I am trying to apply conditional formatting to a cell when it contains an equation with reference to a named cell. Example: Cell I71 contains the following equation. =G71*Admin_Labor_Rate Admin_Labor_Rate has a value of $50, and is the name of cell B152. Now I want to find all cells that reference cell B152 "Admin_Labor_Rate" and apply conditional formatting (highlight). I have two other Labor Rates, so I want to use cell highlighting to distinctly identify if the labor is being performed by technicians, admin, or engineering. I have done a lot of research and tried a lot of methods, but it seems as close as I can get is if the cell equates to a certain value, then I can format it. Thanks in advance for any thoughts the community may have on this.
Use this formula with conditional formatting: =ISNUMBER(SEARCH("Admin_Labor_Rate", FORMULATEXT(A1))) Where A1 is the top-left cell of the range you want to conditionally format. For example, you select range F20:H30 and enter the formula with F20 instead of A1.
Perhaps a User Defined Function (i.e. UDF). function formulaContains(rng as range, nr as string) as boolean formulaContains= rng.hasformula and cbool(instr(1, rng.formula, nr, vbtextcompare)) end function
Conditional formatting using the INDIRECT function fails with boolean AND or OR or with cells containing formulas
I have the following function for checking whether column L contains the word "completed" and I use INDIRECT to be able to color the whole row with Conditional Formatting: =INDIRECT("l"&ROW())="completed" This function works. However, I need to extend this, I want to use Conditional Formatting based on an extra cell as well, so I tried this: =AND(INDIRECT("l"&ROW())="completed";INDIRECT("m"&ROW())="duplicate") When I use this second function inside the Excel worksheet they give the proper TRUE or FALSE. Furthermore, I needed a Custom Formatting on the result of a formula in a cell. I tried the following: =INDIRECT("n"&ROW())=123456 This only worked if I removed the formula in the cell with the result itself as a number. Again, the function worked when pasted in an worksheet cell. Is there a way to make this work inside Excel or is there a limit to what Conditional Formatting functions can do? In case you ask: AND(1;1) works and makes everything yellow, AND(INDIRECT("n"&ROW())=123456;1) does not work, nor does replacing AND with OR. The semicolon is because I am in the Dutch locale. Replace it with a comma if you are in an English locale.
Not sure why this wouldn't work in Conditional Formatting. But you can simply replace the AND function with * such as: =(INDIRECT("l"&ROW())="completed")*(INDIRECT("m"&ROW())="duplicate")
You have to think in terms of xlR1C1 formulas to understand CFRs. A CFR based on a formula thinks of it as =RC12="completed" or more completely =AND(RC12="completed", RC13="duplicate"). The xlR1C1 formula does not change no matter what cell you paste it to; it is in this way that CFRs can be applied to a wide range of cells without expending calculation cycles to update the formula for each individual cell. RC12 means 'the cell in column L on the row you are on'. It does not change if filled down, filled right or copied to any other location. Now unless you are actually working in xlR1C1 (File, Options, Formulas, Working with Formulas, R1C1 reference style) you have to convert the xlR1C1 to xlA1 style. If you are applying the CFR to a number of rows starting with the first row then the R becomes 1 and the C12 becomes $L. 'xlR1C1 =AND(RC12="completed", RC13="duplicate") 'xlA1 =AND($L1="completed", $M1="duplicate") If you were applying the CFR to a range starting in row 2 change the $L1 to $L2 and the $M1 to $M2. Among other reasons for not putting the xlR1C1 style formula directly into the CFR creation dialog when working in xlA1 style is that there actually is a RC12 cell in xlA1.
Using IF Function Range in Excel
I have some problem in using If Excel function. I want to use range in excel. So when my data is in range, it will show something. I use this formula but it doesn't work " =IF(E11=Rekap.C8:C21, VLOOKUP(Rekap.C8:C21, Master.A2:C148, 3), "") Form that formula, if data in E11 is same like data in range C8 - C21 in Rekap sheet, it will show another data in Master sheet that in range A2-C148 column 3. How can I use range in if formula ?
A single cell like E11 cannot be compared to a range like C8:C21. I assume that you really want to check if the value in E11 appears anywhere in the range C8:C21 and if so, perform the lookup. That can be done in several ways =if(isnumber(match(e11,Rekap!$C$8:$C$21,0)),vlookup(E11,Master!$A$2:$C$148,false),"") Note that I added the fourth parameter to the Vlookup. It will default to TRUE if omitted, which may return wrong results if the lookup table is not sorted.
Excel - Adding a row outside of forumla range
Currently I have a couple of SUM functions setup in my worksheet. Lets use H2:H34 for my example: If I add a row within that range, the sum function will automatically adjust. The problem is when I add new rows, it is below the range (below H:33). In this case, I would just have to highlight the column and expand/drag the range to where it needs to be. There are a total of 8 columns that are doing a sum function. Is this only possible by using a macro? =SUBTOTAL(3,H2:H34)
With your formula being the extent of the range minus one row we can use this: =SUBTOTAL(3,H2:INDEX(H:H,ROW()-1)) Now as rows are added or deleted the reference will remain intact. If there is a chance that row 2 would be deleted you will get #Ref errors. To avoid that you can use this formula: =SUBTOTAL(3,INDEX(H:H,2):INDEX(H:H,ROW()-1)) Now there are no specific cell references and adding or deleting will not effect the formula and the range will be dynamic.
you could use a named range like =sum(range1) and something like; Select first empty cell in column F starting from row 1. (without using offset ) to find the first empty cell to change the reference for the named range. Triggering it would be difficult... potentially could use on_save? or option 2.... bit of a dodge, but can work.... you say your sum is in cell H35... maybe move it to h36, and create a dummy hidden row in 35 (0.1 row height). that way when you add a row, it is always above 35. Use sum H1:H35 and it will always auto update? its not a neat solution, but should work
Use the following code, you need to adjust column "H" to whatever column you need. Dim sumtest As Variant sumstest = Application.WorksheetFunction.Subtotal(9, Range("H2:H" & ActiveSheet.Cells(ActiveSheet.Rows.Count, "H").End(xlUp).Row))
Array Formula To Return List Based on Multiple Conditions
I have a spreadsheet that looks like the picture below. I have some formulas that perform counts on this sheet and compare this data to another data source. An example of one of these would be: =Countifs(A2:A10676,"0",C2:C10676,"OPEN",D2:D10676,"Current") How would I return the list of loan numbers associated with the count? For instance, the count above returns 3038. I tried the below formula. I selected C2:C3039, typed the formula and hit Shift + Ctrl + Enter: =If(And(A2:A10676="0",C2:C10676="OPEN",D2:D10676="Current"),B2:B10676,"") My thought was that this evaluates the logical for each line and builds an array of the values in column B. When I enter this, each cell in the array is blank. Can someone please explain how to return an array with values based on multiple criteria?
I see two problems with your formula =If(And(A2:A10676="0",C2:C10676="OPEN",D2:D10676="Current"),B2:B10676,"") Firstly you can't use AND to return an array - AND (like OR) returns a single result (TRUE or FALSE), so you need either nested IFs or to use * to simulate AND, i.e. either =IF(A2:A10676=0,IF(C2:C10676="OPEN",IF(D2:D10676="Current",B2:B10676,""))) ....or..... =IF((A2:A10676=0)*(C2:C10676="OPEN")*(D2:D10676="Current"),B2:B10676,"") Note: I used 0 without quotes for the first criteria - for COUNTIFS you can use "0" or 0 but here it needs to match the data type - only use quotes if the data is text formatted - I'm assuming that isn't the case The second problem is that for both of those the resulting array still has 10675 values because it still includes all the blanks for rows when the criteria aren't met. To get an array of just 3038 values you can use this formula array entered into the correct sized range: =INDEX(B2:B10676,SMALL(IF(A2:A10676=0,IF(C2:C10676="OPEN",IF(D2:D10676="Current",ROW(B2:B10676)-ROW(B2)+1)),ROW(INDIRECT("1:"&E2)))) Where E2 contains your COUNTIFS formula Note that this only works to return an array in worksheet range - it won't work to return an array to be used in another function
Here is an approach that uses a "helper column" rather than an array formula: In E2 enter the formula: =IF(AND(A2=0,C2="OPEN",D2="Current"),1+MAX($E$1:E1),"") and copy down (this marks the multiple rows meeting the criteria) In F2 enter: =IFERROR(INDEX(B$2:B$24,MATCH(ROWS($1:1),$E$2:$E$24,0)),"") and copy down.
You can set a data filter: Dim wrk As Worksheet Set wrk = ActiveSheet If Not wrk.AutoFilterMode Then wrk.range("a1").AutoFilter wrk.range("a1").AutoFilter field:=1, Criteria1:="0" wrk.range("a1").AutoFilter field:=3, Criteria1:="OPEN" wrk.range("a1").AutoFilter field:=4, Criteria1:="Current" Set wrk = Nothing Of course, you could manually turn on the filters to how you like, too.
Insert four blank rows at the top, copy A5:D6 into A1 and delete B2. DATA > Sort & Filter, Advanced, Copy to another location, List range: A5:D10680, Criteria range: A1:D2, Copy to: F1:I1, check Unique records only, OK.