Excel and VBA formatting without conditionals - excel

Could someone point me in the right direction with a problem please?
I have 2 ranges of values in an excel sheet, (F3:K44) and (N6:S6).
What I'm trying to achieve is when a user enters numbers in range (N6:S6) I want any duplicates in (F3:K44) to change the background colour. Conditional formatting will not suffice as there is only 3 options and I need 6.
Any help appreciated. Thanks in advance.

If a cell in F3:K44 has a match in any cell in N6:S6 then you could change the conditional formatting to a formula to find a match, and use match() formula in there.
Create a new rule on F3 and choose "Use a Formula to determine which cells to format".
In there, enter
=MATCH(F3,$N$6:$S$6,0)>0
Save that and copy the formatting through F3:N44 and you'll be good to go.
That MATCH() formula will look in the second Parameter's range for the First Parameter's value. The 0 in the Third Parameter tells it to only do an exact match (otherwise you'll get some unexpected matching).
An example of this in action:

Related

change cell color with conditional format

I wanna ask about Ms. excel. maybe it will look so basic for someone who always work with excel. so thank you for anyone who help me with this.
I have sheet1 and sheet2. so i want to make cell in column A sheet 1, which have same data exist in column A sheet2 to change color automatically.
I don't know how to make it work so I made column helper in column c sheet1 with this formula
=NOT(ISERROR(MATCH(a2;sheet2!$A$2:$A$1000;)))
and get true if the data exist in sheet2. and then I drag that formula so all column c have this formula.
I thinking using conditional formatting, so I block column A in sheet 1, and make conditional formatting with formula
=C:C= "TRUE"
but this not work. i really a newbie and only study by myself from internet, but i dunno how to search to solve this problem.
any help or advice for this problem?
thank you so much before
You can put the formula that returns TRUE or FALSE directly into the conditional formatting rule.
You should define it on cell A2 first, then change the 'Applies to' range to be all the rows you want to test. If you can, I recommend you try to avoid using references like C:C.
So, supposing you want to test the data in cells A2:A10 on sheet1, then your rule would look something like this:
Note that my locale uses comma as parameter separator and not semi-colon, so you should adjust accordingly.
Try the following formula in CF rule.
=COUNTIF(Sheet2!$A:$A,"*"&$A1&"*")>0

Excel - Highlight cell which is closer and smaller to a specific value

I would like to highlight a cell which is the closest the a specific value but still lower (below) or equal according to a formula.
For instance, if I have 14 in B4, I would like the cell 13 (or 14) highlighted but not 15 in the range.
The value I need to look for would be in B4 and the range that I must apply the highlight formula to would be L1:L371.
So far, the best result I was able to achieve was with (from what I was able to find using Google or Stackoverflow already existing content):
=SMALL($L1:$L317,COUNTIF($L1:$L371,"<="&$B$4))
Although, not only it selects the value I am looking for, it also selects all the values below.
May someone provide me some help so I can achieve the expected result please?
Thank you for your time and help, it is greatly appreciated.
Based on your description, it seems like you need to find the maximum value of a range (L1:L137) that is less than or equal to an input variable (B4) and highlight that value in the search range. Depending on what version of Excel you have, here's what you need to do:
For Excel 2019 or Excel 365
You can use the MAXIFS function. You would actually put that function in a conditional formatting rule, but more on that in just a second. As a test, put the following code in cell B5:
=MAXIFS($L$1:$L$137,$L$1:$L$137,"<="&$B$4)
The first argument is your "MAX_RANGE", or the range that contains the values you want to find the max of. It is also our "CRITERIA_RANGE", the second argument. The third argument is the criteria itself, which is that the search range must be less than or equal to the value in cell B4. Essentially, we are going through the list and creating a subset of numbers that are less than or equal to our search value, and discarding the rest. I assume you are aware of relative vs. absolute referencing, since you used the "$" anchor in your referenced code. If not, here's a description of the difference.
Now, the result of that formula should be the highest number in the list less than or equal to the search value, but that doesn't highlight it for us in our list. To do this we need conditional formatting. To do this, highlight your data range (L1:L137) and go to the conditional formatting drop down on the home tab of the menu ribbon. Choose "New Rule". On the dialog that pops up, choose, "Use a formula to determine which cells to format". In the formula input box, enter:
=L1=MAXIFS($L$1:$L$137,$L$1:$L$137,"<="&$B$4)
This will compare whether the value in the cell being evaluated (L1, for instance) is equal to the result of that formula we talked about above. Since L1 is only relatively referenced, this formula will work for every cell in the data range.
Now, before you hit "OK" on the dialog, select the Format button. This will allow you to adjust your highlighting and formatting as you desire. Click "OK" on the formatting dialog, then "OK" on the Conditional Formatting Rule dialog. This should now highlight any data cell that is equal specifically to the result of our formula, and not everything that's less than our value.
For Earlier Versions of Excel
The concept is the same in earlier versions of Excel, but unfortunately, the MAXIFS function is not present in these versions. Instead, we must use an array formula. Array formulas are a whole other can of worms, but ExcelJet is an excellent resource. In fact, they talk about this very issue, here.
Unfortunately, we can't put the array formula in the conditional formatting formula like we did above, so we'll need to put this formula on a cell in the worksheet, then the conditional formula should reference that new cell. So in cell B5, if you put:
=MAX(IF(L1:L137=B4,L1:L137)
And then, instead of pressing Enter, you must press Ctl + Shift + Enter
This keyboard combination will tell Excel that you are trying to enter an array formula. If you don't press these keys, then the formula will error. Once you have entered the array formula, if you put your cursor in cell B5, you will see the formula bar at the top has added curly braces ({ , }) around the formula to look like
{=MAX(IF(L1:L137=B4,L1:L137)}
This leads to the same result as above, but is just achieved slightly differently. Now, following the same process described above for conditional formatting, you will simply set the formula to:
=L1=$B$5
And that should be it! Hope this helps!

Excel conditional formating - conditional on sum of all previous cells and total sum

I have a question with regards to conditional formatting which I simply can't seem to solve.
The aim is to format the background color for the left-most cells that are blank up until a cell contains a value - and after this there should be no more formatting in this row. You can see an image of the result I'm hoping for beneath:
So far I've managed to create the conditional formatting of the blank rows, but sadly haven't managed to create the "single-cell" formatting (in yellow) conditional of the sum of all the first cells being = 0.
I've created a formula which actually succeeds in calculating the sum of the previous cells, but this formula includes INDIRECT() which it seems that conditional formatting doesn't allow. At least I'm getting an error starting with the follow (translating the error from Danish to English might not be intuitive):
You cannot use reference operators such as.....
The formula I'm trying is the following:
=AND(SUM(A2:INDIRECT(IF(COLUMN(A2)>=27;CHAR((64-26)+COLUMN(A2))&CHAR((64-26)+COLUMN(A2))&ROW(A2);CHAR((64)+COLUMN(A2))&ROW(A2))))>0;$K2>0)
Where $K2 is the sum of the row.
Is there a way to SUM a range of cells by doing something similar to this:
=SUM(B2:CHAR((64)+COLUMN())&ROW();"")) to dynamically SUM the range from B2 to the current cell? The problem in this case is whether the part CHAR((64)+COLUMN())&ROW();"") can be converted into a legible cell such as B4 to make it work inside the =SUM() formula?
Sadly the =ADDRESS() formula cannot be used (as far as I know) as this will trigger the same error in conditional formatting as well.
For now I would like this to work with the regular Excel conditional formatting, but if anyone have a simple VBA this would also have interest - however, I would by far prefer the regular solution.
The question:
Is there a way to create a formula that doesn't trigger this error - maybe by refrasing the formula or doing something completely else?
It seems to me that this could be handled with a much simpler CFR formula like,
=and(not(sum($a2:a2)), $k2)
Am I missing something?

Copying conditional formatting with VLOOKUP across columns

I am formatting cell D25 using the following conditional formatting formula:
=(VLOOKUP($C25;$C$6:$L$18;2)+D25)>32
When applying the formula to the adjacent column I get formula updates to
=(VLOOKUP($C25;$C$6:$L$18;**2**)+E25)>32
Using the Copy and Paste Format function works mostly i.e. references in the formula are updated as I would expect.
The only (essential) thing that doesn't update is the INDEX value in the VLOOKUP formula. I would expect this value to increase by 1 when copying the format to the next column - it doesn't.
Is there any way to go around this issue with VLOOKUP? Is there a better suited formula to achieve the same result?
Any help will be greatly appreciated!!
This value does not increase automatically, and it is good. This formula was designed to be used on Tables, so consistency is a point here.
For conditional formatting, you may want to use $ to lock some references. For example, let we have the simple sheet as below:
First, select the range in the CORRECT order. This is important. the first cell you select will be reference for offsets of the conditional formatting. For this example, let's do it like this:
Now, let's go for the conditional formatting itself! Conditional Formatting > New Rule... > Use a formula to determine which cells to format. And let's put this formula:
=if($A1<=2;TRUE;FALSE)
Click OK and...
There we go! We just formatted the lines in witch An is equal or less than 2! Please note that we only had to lock the COLUMN of the reference. So, logically, to format the columns we would have locked the ROW.
Hope it helps!
EDIT:
If you REALLY want to use VLOOKUP, which I DO NOT recommend, you can just use the formula:
=(VLOOKUP($C25;$C$6:D$18;COLUMNS($C$6:D$18))+E25)>32
To change the index dinamically.

Excel conditional formatting based on cell content

I am trying to write a conditional formatting formula for the rule "if the first cell of this row is NOT empty AND the current cell IS empty".
Basically I am trying to bring attention when a user has forgotten to enter a value in a cell.
The formula I came up with was:
="NOT(isblank($A1)) AND isblank(A1)"
Please provide an explanation why my formula is wrong, not just the correct formula =)
The logical "AND" is not an operator in Excel, it is just another function. Excel doesn't know how to evaluate =FUNCA() AND FUNCB(). Instead, wrap the two functions inside the AND function:
=AND(NOT(ISBLANK($A8)), ISBLANK(M8))

Resources