Using an array based formula in conditional formatting - excel

What I am trying to do with excel is a bit unorthodox, but I need a method of cleaning the data people import in to TechExcel's DevTrack. DevTrack creates values for fields if what you attempt to import is not 100% accurate to what exists already in the project, leading to duplicate values with slightly different formatting.
What I have come to is having a "validator" excel sheet; people copy/paste what they want to import, and anything that doesn't match a data validation table is highlighted.
Data validation itself does not work because copy/paste overwrites it and it is a waste of time to enter data manually.
I have managed to get conditional formatting working partially using this formula:
=ISERROR(MATCH(C5,D:D,0))
However it is not case sensitive. I need case sensitivity.
So I managed to create another formula which shows true if there is no match, however exact requires it to be an array formula which doesn't seem to work with conditional formatting.
So this works if it is entered in to a cell with ctrl+shift+enter, but doesn't work as a conditional rule.
{=ISERROR(MATCH(TRUE,EXACT(C5,D:D),0))}
Here is a simplified version of what I'm looking at for testing. That formula is true when there is no case match, but I can't enter it in conditional formatting with ctrl+shift+enter. If this worked as I want it to, the lower case "melon" would highlight red.
Is there a way to get this working, or is there an alternative method to do this?
If it matters, I'm using the latest version of excel in office 365.

Use a function that produces array processing without CSE. Examples are SUMPRODUCT or AGGREGATE (among others).
'to show TRUE for case-sensitive matches
=SIGN(AGGREGATE(15, 6, ROW($D$5:$D$9999)/EXACT($C5, $D$5:$D999), 1))
'to show TRUE on no case-sensitive match
=ISERROR(AGGREGATE(15, 6, ROW($D$5:$D$9999)/EXACT($C5, $D$5:$D999), 1))
The SIGN wrapper is unnecessary but for me it is a visual reminder that I'm looking for a boolean.
You cannot use dynamic ranges like D5:INDEX(D:D, MATCH("zzz", D:D)) in a CFR and you do not want to use full column references in AGGREGATE (or SUMPRODUCT) so I opted for $D$5:$D$9999.

Related

Why does my Conditional Formatting fail when it works in Worksheet? Possible INDIRECT issue?

I am trying to do a comparison/Conditional Formatting between columns based on a drop-down choice. I have a formula that works fine in the spreadsheet, but does not seem to be working in my Conditional Formatting formula. Is INDIRECT causing my issue?
Formula is:
=IF(H1>100, IF((H1-INDIRECT(ADDRESS(ROW(H1), MATCH($H$4,$A$3:$I$3,0))))/((H1+INDIRECT(ADDRESS(ROW(H1), MATCH($H$4,$A$3:$I$3,0))))/2)>$J$2,TRUE,FALSE),FALSE)
Kind of hard to read, but the part that broke it is trying to grab my comparison cell using the following:
INDIRECT(ADDRESS(ROW(H1), MATCH($H$4,$A$3:$I$3,0)))
Where $H$4 is my drop-down value. So I am selecting the column that contains the data I want to compare to, then using address to select the current rows cell, then accessing it with INDIRECT.
If I replace the INDIRECT part with an actual cell, everything works as it should as well.
When I use the first formula, everything looks great if I input it into a cell on the worksheet, but I would rather not dirty it up if I don't have to. Is there a way to make this work?

Excel - conditional formatting with multiple criteria doesn't work

I'm trying to color a cell red when the contents matches (at least) one of two other cells.
I've been trying this:
=AND(COUNTIF(CB17:CE17;CB55)=1,COUNTIF(CB18:CE18;CB55)=1)
and this:
=AND(COUNTIF(CB17:CE17;CB55)=1,COUNTIF(CB18:CE18;CB55)=1) = TRUE
but Excel doesn't recognize this as a formula ("There's a problem with this formula. Not trying to type a formula? ...")!
I can't get any conditional formatting formula to work with the AND operator it seems (and my Excel is the English version).
Any advice?
Edit:
some screenshots to clarify:
Error I get when using AND or the '+' operator in the formula:
Current contents of the criteria cells:
AND will be true of the expression inside results to true.
First of, you do not need to evaluate to 1 for AND to work. Secondly, you used ; and , instead of ;. You mentioned changing them to ; solved it.
So =AND( COUNTIF(...), COUNTIF(...) ) would already be enough.
Your formula would be =AND(COUNTIF(CB17:CE17;CB55);COUNTIF(CB18:CE18;CB55))
Now that being said, you want it to work for either of the values being true, that means you need an OR operator, not AND. The syntax is basically the same, just replace AND with OR. Your formula would be =OR(COUNTIF(CB17:CE17;CB55);COUNTIF(CB18:CE18;CB55))
Now since your ranges are CB17:CE17 and CB18:CE18 and they both evaluate to CB55, you could of course simply use =COUNTIF(CB17:CE18;CB55) which would be a lot simpler. I have explained the AND so you can learn from it, in case you really need to use more ranges and/or evaluate against different cells.

Conditional Formatting exact text match

I have several spreadsheets where I want to highlight all the rows where the data matches a separate list. I have used a rule for this but it's not highlighting it exactly; it's just matching part of the word, for example General manager in one list is highlighting Manager in the other list whereas I would only want it to highlight General manager.
This is the formula I've used:
=COUNTIF(A92:A400,L2:L196)
and I've also tried MATCH but it pulled out out even more incorrect matches.
You will have to bring in the EXACT function somewhere.
    
This CF rule was created by selecting A1:D7 and creating a rule based upon the following formula,
=AGGREGATE(15, 6, ROW(1:1)/EXACT($A1, $F$8:$F$10), 1)
The way I interpret the question is that case sensitivity may not be required, rather that use of wildcards may be causing issues (ie that exact text match is not applying "exact" in quite the same way the EXACT function does). If the separate list is the one in ColumnL then please select from A92 to A400 and HOME > Styles - Conditional Formatting, New Rule..., Use a formula to determine which cells to format and Format values where this formula is true::
=COUNTIF(L$2:L$196,A92)
Format..., select your choice of highlighting, OK, OK.
If to be applied to several sheets it may be convenient to Name the L2:L196 range.
The above highlights cells rather than rows, but that could be adjusted.

IF function - is there a way to avoid repeating formula

Can't believe I don't know this, but is there a way to avoid repeating a formula in an if statement if the logical test is dependent on it?
i.e.
=IF((SUMIFS formula)=0,"",SUMIFs formula)
I want to replace that SUMIFS function in the false scenario with something short that will tell it to just programmatically repeat the formula it originally tested for. Repeating the formula twice has to have detrimental effects on processing speed. Negligible, maybe, but want to go for best-practices here. Thanks.
You can force an error like #DIV/0! and then use IFERROR, e.g.
=IFERROR(1/(1/SUMIFS_formula),"")
You can assign a Name to a formula and use the Name..............See:
Assigning a name to a formula
Relevant excerpt -
For example, let's suppose we frequently use a formula like:
=SUM(A1:A100)-SUM(B1:B100) and this resides in A101 and is copied across many columns on row 101. It would be better in this case to
create a custom formula that does this in each cell on row 101. Here
is how;
1) Select cell A101 (this is vital).
2) Go to Insert>Name>Define and
in the "Names in workbook" box type: SalesLessCosts
3) Now click in
the "Refers to" box and type: =SUM(A1:A100)-SUM(B1:B100) then click
Add.
Now you can replace the formula in cell A101 with: =SalesLessCosts.
You can also copy this across row 101 and it will change its relative
references just as the formula =SUM(A1:A100)-SUM(B1:B100) would. The
reason it does this is all down to the fact we selected A101 before
going to Insert>Name>Define and used relative references in
=SUM(A1:A100)-SUM(B1:B100) when we added it to the "Refers to" box.
If all you need to do is hide zeroes, there is an easy way:
Select all cells where you wish to hide zeroes
Go into Custom Number Formatting
Set format to "General;General;"
The custom formatting has a structure of [positive numbers];[negative numbers];[zeroes]
By making the last part blank you are effectively hiding zeroes, but showing everything else.
The advantage over conditional formatting is that you can use this on any background.
A neat trick which I sometimes use is to hide the cell value completely by using a custom format of ";;;". This way you can put images inside the cells, like the conditional formatting ones, and not see the value at all.
Try using the SUBSTITUTE function like this :
=SUBSTITUTE( VLOOKUP( H4; $D$5:$E$8; 2; 0 ); $H$1; $I$1 )
Here is an example:
Here the formula I don't want to repeat twice is the VLOOKUP function.
The result of VLOOKUP is a string found in another table (ex : "Green").
I want to check if that string matches a specific string value in $H$1 (here, "Yellow").
If it does, SUBSTITUTE replaces it with$I$1 (the error string you want. Here, "FORBIDDEN").
If it doesn't, it displays the VLOOKUP result string (the normal authorized output, like "Green").
This is useful for me because my actual formula is quite long, so I don't want to write it twice.
I also dont want to use two different cells, because I'm already applying this formula on 10 columns, meaning I should add an extra 10 columns to make it work.
In some scenarios, MAX() or MIN() can do a wonderful job.
E.g., something like this:
=IF(SUMIFSformula>0,SUMIFSformula, 0)
Can be shortened to this:
=MAX(0,SUMIFSformula)
The LET formula can be used for this exact scenario. You can define the formula as a variable and then within that same cell you can reference the variable in your formula.
The LET formula format looks like this:
=LET(name,name_value,calculation)
SUMIFS Example
Here's how it would work with your SUMIF example so that you don't have to repeat the formula:
In this screenshot we have an array A1:B7. We want to sum the values (Col B) if the name in ColA is "apple".
For this we have a standard SUMIFS formula of
=SUMIFS(B1:B7,A1:A7,"apple")
The formula is showing in E2. The result is shown in E3.
To put this into the IF statement without having to repeat the formula we can use LET as shown in the screenshot.
We create a variable with the SUMIFS formula as the value of that variable. We then write our IF statement using the variable name instead of rewriting the formula multiple times.
=LET(name,name_value,calculation)
Variable name: sumapples
Variable value: SUMIFS(B1:B7,A1:A7,"apple")
Calculation: IF(sumapples=0,"",sumapples)
Put together in the LET function it looks like this:
=LET(sumapples,SUMIFS(B1:B7,A1:B7,"apple"),IF(sumapples=0,"",sumapples))
This LET function can be used in any Excel formula, and is very useful for shortening long formulas that have repetition.
Optional: Extra complexity
If you want to you can get extra complicated by naming multiple variables.
=LET(name,name_value,name2,name_value2,calculation)
Since Excel 2007, the IFERROR statement does what the OP asked. From the help file:
Description:
Returns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula. [italics mine]
Syntax:
IFERROR(value, value_if_error)
I've since realised that this was already answered by #barry houdini above.
Here is a hack - depending on whether you are just interested in the displayed value, or whether you need to use the value in another formula:
Put your SUMIF formula in the cell (without the IF part)
Create a conditional formatting rule which sets the font color to the background color when the cell value is 0
And hey presto, you get the desired result.
As I said - it's a hack, but it does prevent the double evaluation.
There is no "clean" solution that I am aware of.

Conditional data validation for MS Excel

i read some tutorials that help out with conditional (or dynamic) data validation, but its usually dynamically generating list item choices based on previous selection etc.
what i want is, lets say i have
columnA : columnB
telephone_number : 911
name: peterparker
is it possible for me to dynamically specify data validation rules on columnB based on what is selected in columnA? if its telephone_number, i want to check that the corresponding cell in columnB is a natural number, and if it is a name,i want to check for a string for a certain length. of course i limit the string options that the user can input in columnA.
Following formula on custom validation rules will do:
=IF(A1="telephone_number";ISNUMBER(B1);IF(A1="name";LEN(B1)=8;TRUE))
This is example for cell in B1. You may choose a wider range and combine $ to adapt you formula to all range.
An alternative to data validation is Conditional Formatting. The benefit of the latter is that it is more versatile. We can have the following setting:
Then if we define a name, DynamicValidation as follows:
the formula at the validation box is
=EVALUATE(SUBSTITUTE(VLOOKUP(Sheet1!$A2,Sheet1!$D$2:$E$3,2,0),"()","("&ADDRESS(ROW(),2)&")"))
EVALUATE cannot be used in any sheet cell, but it can be used in Named ranges. However, you will have to save your book as macro-enabled, because it is a legacy macro, originating from Excel 4.0. What it does is the following:
Looks at the value in List1 and finds the formula that needs to be checked (VLOOKUP).
Subtitutes "()" with the cell value of interest (and adds back the parentheses).
Then if you open a conditional formatting box (Home tab, Conditional Formatting, New Rule, Use a formula to determine....) and input the formula =Not(DynamicValidation) like this:
then each cell that does not adhere to the formula will turn red. I tried that with data validation as well, but it does not work unless we build the depencency tree every time we change List 2.. I am not sure why.. But only conditional formatting works :) Here are some screenshots:
The benefit is that we can change the validation criteria without hard-coding.
I hope this helps!

Resources