Check if value in selection is part of set of other values - excel

In Excel I have the following setup:
My Data (=Selection):
A,B,C,D,E,F,G
3,88,64,2,102,5,7
7,8,13,55,203,4,6
1,4,5,8,12,113,99
A set/pool of numbers:
3,7,1,55,22
Now I would like to check if any value in the set/pool of numbers is
in the data (selection) and color code it if so.
I believe this should be doable with conditional formatting.
But I do not want to add a seperate conditional formatting for every number.
But rather use a formula or anything concise.
Thanks.

With your data set up like this:
You can use the following approach:
define a named range myPool referring to I1:I5
select A1:G3, add conditional fomatting rule, choose use formula to determine which cells to format and enter:
=COUNTIF(myPool,A1)>0
choose background color and confirm
This will highlight values from I1:I5. To make it more universal, you can change definition of myPool to (adjust worksheet name):
=Sheet1!$I$1:INDEX(Sheet1!$I:$I,COUNTA(Sheet1!$I:$I))
In this case the named range will dynamically grow when you enter additional numbers in I6, I7, ...

Related

How to color a cell based on the colors in a row with conditional formatting or VBA

I'm trying to color column A (The Ys) based on the rows 1-6. I want it so if it is both green and red to turn yellow, just green to turn green, and just red to turn red. The picture shows the basic idea of what I want.
I'm unaware of any condtional formatting formulas that could make this possible currently. I've scoutted this site on info on VBA and trying to learn it for this. If you can solve this can you please explain each step so I can understand it better for the future.
Interestingly, there is a way to do this with Conditional formatting, but that uses a little-known trick that Excel has: the GET.CELL function (more info).
This function cannot be used in a cell, but it can be used in a named range, so the idea is to create a named range, give it a name like "BackgroundColorIndex" and define it like this:
=GET.CELL(63,INDIRECT("rc",FALSE))
You can then create a sheet named "Color" where you define your colors:
Where each Index is determined by using the BackgroundColorIndex function.
I would then suggest to create named ranges for each color (GreenIndex, YellowIndex and RedIndex), so we can refer to them later.
Now, we are going to need to create another version of BackgroundColorIndex, but instead of referring to the cell itself, it will always refer to the corresponding cell in the sheet where you have your data.
Let's call it BackgroundColorIndexSheet1 with the following definition:
=GET.CELL(63,INDIRECT("Sheet1!rc",FALSE))
(Note that you need to replace "Sheet1" with the name of your sheet.)
Then, you would create a new sheet. Let's call it "Sheet2". It will be where we do the calculations.
It that sheet, column A and headers would be identical to Sheet1, but the formulas inside would be =BackgroundColorIndexSheet1
For instance, in my case, I have the following values.
And we can then add a few helper columns that will look like this:
The formulas :
J2: =SUMIF(B2:G2,">0")/MAX(COUNTIF(B2:G2,">0"),1)
K2: =IF(J2=GreenIndex,GreenIndex,0)
L2 : =IF(J2=Redindex,RedIndex,0)
M2: =IF(SUM(K2:L2)>0,SUM(K2:L2),IF(J2>0,YellowIndex,0))
Now we can use the values in the output column in our conditional formatting rules. For instance:
And the outcome would be :
⚠ You will need to press F9 to refresh the calculations when values change.
⚠ You will need to save your workbook as .xlsm since we are using GET.CELL

Conditional Formatting not enough

I'm trying to set conditional formatting in a specific group of cells J9:N12 with a locked cell I9 (110). In Cells J9:N12 I need the conditional formatting to set 1,2,7,8,13,14 as Black Fill w/ White Text, 3,4,9,10,15,16 as Red Fill w/ Black Text, 5,6,11,12,17,18 as Blue Fill w/ White Text. Then if I Change (I9) to 277 the Fills would change to reflect Brown/Orange/Yellow in place of the Black/Red/Blue.
Yes, I can Conditional Format the cells I need based on the information set in cell (I9) 110 or 277.
The series of numbers I need to format is greater than 120. I cannot set Conditional Formatting for each specific number needed. Minimallistically I need to be able to set Conditional Formatting to around 150-160 numbers.
I don't know if I need to utilize VBA or if Conditional Formatting is the way to go.
You could use conditional formatting for this. I'd be tempted to put the number series in an array and test for a find in the array using MATCH. This way, you'd only need as many conditional formatting rules as there are number series.
I'm not certain, but I believe you can't write an array directly into a conditional format rule, but you could refer to it from something like a range name. In any event, a range name would be easier to manage if you needed to change any of the number series.
For example, in the black/brown case, you could create a range name (Formulas->Define Name), called black-brown, and in the Refers To window, have the formula:
={1,2,7,8,13,14}
Then your conditional formatting rule would be something like:
=AND($I$9=110,NOT(ISNA(MATCH(B2,black_brown,0))))
Note my cell to be tested is in B2 - change that to whatever you need.
You'd just add rules for each of your number series cases, as shown below:

Excel Change Cell Color when Default Text Changes

I have an Excel worksheet with cells that contain the following default text:
Initials:
Time:
Pt Name:
These three lines above are the contents of a single cell. Each of these values may be filled in at any time. For example:
Initials: MR
Time: 1800Z
Pt Name: Doe, John
How can I highlight any cells whose values are changed? That is, not the default text? I looked at Conditional Formatting, but it doesn't seem to offer a "change event" or some such option.
The easiest way to accomplish exactly what you're asking is to use conditional formatting with a "defaults" worksheet (especially if you're going to have a few cells to setup like this, and the default values are subject to change), like this :
1. Set up a "Defaults" worksheet that will hold your default values
2. Set up the conditional formatting on the concerned cells
3. Repeat for other default values!
As commented, you can try this:
Edit1:
Create a named Range like below.
In this example, I used A1 and named it Template.
Then use formula in conditional formatting like this:
Then set the Applies to to the entire range of interest like this:
Then there you go. If it is not equal to Template then it will be highlighted. HTH.

Copying conditional Formatting in Excel

I use conditional formatting to format a cell depending on the values of another cell. This is the rule:
Cell Value not between =$BV$10*0,5 and =$BV$10*0,5
This rule is saved on Cell Y10
(Explanation: If the Value in Y10 is inbetween 0,5...1,5 * BV10 apply the formatting)
I want to use this rule on many different Cells but the formula should adjust automaticly, just like in a "normal" formula.
When I copy the format using the Format Painter the formula is copied without any changes. But I need the row to be changed. For example, when copying to Y11 the formula should be changed to :
=$BV$11*0,5
Is there any way to achieve this or to change $BV$10 into $[this column+83]$[this row] or something like that?
Yes. $ is used to lock the cell reference.
So to get what you need just change your formula to this unlocking the rows:
=$BV10*0,5 and =$BV10*1 ~~> I change the limits to actually test the formula
So if you want your column to move as well, then remove the other $ sign.
Also, you can explicitly apply this formatting to other cells by supplying the range in Applies To argument like below:
Take note that you can actually put the formatting in any cell.
But the effect will always be on the Range you explicitly define in Applies to.
I discourage using the Copy Paste Format as this sometimes overlaps formattings you've done.
To apply the formatting to a group of different range, just separate the ranges with a , comma like what you see below:
So the formatting will then be applied to $Z$10:$Z$20 as well.
It is the same as $Y$10:$Z$20, but I just want to point out that it can be used to none contingous range.
And since your column is locked with your formatting, it will still be references to $BV(x) where x is the corresponding row in Y and Z.

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