Formatting so that cell is colored differently if it matches any value in column A, or column B, or both? - excel

I have tried solving this myself for some time and it just isn't working for me. It's a somewhat specific goal I have so I haven't had much success finding examples online, so I'm hoping for some direction on how best to approach this. I'm hoping to find a solution that uses VBA. I'm pretty new to VBA so bear with me please!
I am dealing with conditional background coloring based on matching cell values. I have three variable-length columns: A, B and D. Columns A and B are randomly selected subsets of the values that are in column D - so, the values in the different columns may match, but they probably won't be on the same row.
When a cell's value in column D matches that of a cell in column A, I want that cell's row from column D to column K to be colored blue. Likewise, if the cell's value in column D matches a value in column B, I would like it colored red. If a cell in column D matches a cell in both column A and B, I would like it colored purple.
Does that make sense? How would you suggest I approach this?
Let me know if I need to clarify further. I would greatly appreciate any help!
Using Excel 2013.

I have not actually seen your file, since I am at work, but I guess your table looks like this:
| A | B | C | D |
| 1 | 3 | | 1 |
| 3 | 5 | | 2 |
| 2 | 4 | | 3 |
| | | | 4 |
| | | | 5 |
I rather like simple formula based approaches for that, but I could give you a vba example too.
With this setup I propose to use VLOOKUP. You basically check, if the value is part of A, part of B and then you can do the rest with your conditional formatting.
So if additional columns are no problem, just use the lookup to generate a true or false answer (I apologise for formula mistakes, since I use a german excel version):
=NOT(ISERROR(VLOOKUP(D1,A:A,1,False)))
This will tell you TRUE, if there is a value in ALL of column A, that is equal to D1. If you also use this formula for column B you can base your colorcoding for blue and red on these two.
For the purple color you just need to compare the other two results again with a simple AND
Hope that is clear enough and I have read your question right.
Kaz

Related

Excel - Tell if Column A a third of Column B

I'm drawing a blank how to do what I think is a simple formula with a color change.
I have two columns see below
A | B
------
3 | 9
25| 10
I want to change the value in Column A is a third of Column B so the first row the 3 should be highlighted in red where as the second row just be left alone. I have tried MOD, IF statements to keep it simple but just tripping over myself.
Any pointers to functions or a start of a formula at a high level like IF(column b / column a) will lead me to my answer be appreciated.
Thank you for your time.

How to find if value exists in column 2 given criteria for column 1?

So you know how there is a sumifs function where you only sum the values in which each column's criteria is met?
What is the formula for finding if a value exists in the spreadsheet after each column's criteria is met?
For example:
Column A | Column B
A | Green
A | Blue
A | Green
B | Red
B | Red
B | Red
B | Green
B | Yellow
C | Blue
C | Green
C | Red
I want to find if Blue exists given that column A's value is "B" In this case it does not exist. I prefer not to use VBA if possible.
Given I am understanding your question properly I would give this formula a try.
You can use the COUNTIFS function to achive your desired result. Just place this formula anywhere except columns "A" and "B" in the same sheet.
=COUNTIFS(A:A,"B",B:B,"Blue")
You can nest your COUNTIFS into an IF statement to produce a more readable result.
=IF(COUNTIFS(A:A,"B",B:B,"Blue")>0,"Found","Not Found")
EDIT: Included IF statement

How to make Excel "IF" formula calculate blank cells as "0"?

How do I make the IF function consider blank cells as "0".
Here is the formula I am using in the H column cells: IF(E1>F1,"YES","NO")
Here is the specific Example:
E | F |G | H |
10 | 0 |30 | YES |
10 | 5 |10 | YES |
10 |-------|-------| NO |
H3 should return "YES" I would think.
In this scenario I cannot change the blank cells to "0", they have to remain blank.
What would be the correct formula for me to use?
I have tried searching around on google and stackoverflow, but the only things I can find are where people are trying to NOT have blanks be considered "0".
=IF(ISBLANK(F1),"YES",IF(E1>F1,"YES","NO")) - Will check for a blank cell, this will work if column F is not formulated
=IF(F1="","YES",IF(E1>F1,"YES","NO")) - Performs a similar check but for the set value "" which is a formulated forced blank cell
=IF(ISNUMBER(F1),IF(E1>F1,"YES","NO"),"YES") - Sense check for if the cell is a number (In case the formulated column is a numerical calculation)
The excel handles automatically for blank cells .
If you enter text it will show error and suggest for correction.
the formaula i use in this examle is
=IF(A1>=B1,"Yes","No")
The result appear as follow

Increment count in column based on value in column

I've 2 columns A and B. A contains names and B contains the count of those names till that record as shown below.
-----------------------------------
| A | B |
-----------------------------------
1 | Fruits | 1 |
2 | Flowers | 1 |
3 | Fruits | 2 |
So, want to have a formula for this. Expecting an array formula. Even if an array formula is not possible, a general formula
Attached a spreadsheet so that it can be explained better.
https://docs.google.com/spreadsheets/d/1wlWqdFwgv90s50iP-bXXBHciyualohj610qFiSatcmQ/edit#gid=1997586177
You do not need an array formula, and I would avoid them when possible. You can accomplish your task with
=COUNTIF(A$1:A1,A1)
Where A1 if the first value in the column of values you want to count. The $ allows you to anchor the top of your COUNTIF range while leaving the bottom dynamic.
In a google spreadsheet you may want to try:
=ArrayFormula(iferror(SORT(ROW(A1:A),SORT(ROW(A1:A),A1:A,1),1)-MATCH(A1:A,SORT(A1:A),0)-ROW()+2))
Example sheet

Excel Function Help - Compare 2 Cells in Worksheet to 2 Cells in another worksheet, if they match, return value from a different column

I'm wondering if someone would be able to offer some advice on the best way to do this please:
Data in Worksheet # 1
Col A | Col B | Col C
Part-1 | 8 | 2
Part-2 | 7 | 7
Part-7 | 9 | 4
Part-8 | 2 | 6
Data in Worksheet # 2
Col A | Col B | Col C
Part-1 | 8 | *Return value* (If Part-1 is found and 8 matches, return 2)
Part-2 | 7 | *Return value*
Part-3 | 8 | *Return value*
In Worksheet#2 in Cell C2 - I would like to check if the Part-1 in A1 is found in Col A in Worksheet#1. If it is, then I would also like to make sure the Number is B2 in Worksheet#2 matches the Qty in Col B next to the same part#, if both the Part# and Qty match, then i would like to copy across the value from the corresponding cell in Col C in Worksheet#1, to Col C in Worksheet#2. If it does not match, I would like it to return a 0.
Here is the a variation on Reinier's second approach in a form that will work in any version of Excel. You can use references to the specific data ranges, as I have done here, or to entire columns.
=SUM((A2=Sheet1!$A$2:$A$5)*(Sheet2!B2=Sheet1!$B$2:$B$5)*Sheet1!$C$2:$C$5)
This is an array formula, so it needs to be entered with the Control-Shift-Enter combination. It performs the same operation as the SUMPRODUCT. (There are several other ways to do this, such as using MATCH with INDEX or OFFSET.)
Essentially, what you are doing is a lookup based on values in two columns. Looking at it from that angle, you can use a the SUMPRODUCT function, which is supported in any version of Excel. Enter the following in Sheet2, cell C2:
=SUMPRODUCT((Sheet1!$A:$A=$A2)*(Sheet1!$B:$B=$B2)*Sheet1!$C:$C)
Select and drag down the right-bottom corner of C2 to complete column C.
This only works by virtue of the fact that the values in Sheet1, column C, are numbers. It breaks if value pairs in column A and B of Sheet1 occur multiple times, but you did not address that situation in your question in the first place.
For versions 2007 and up, you can use the more convenient function SUMIFS with basically the same approach:
=SUMIFS(Sheet1!$C:$C,Sheet1!$A:$A,$A1,Sheet1!$B:$B,$B1)
Alternatively, you can use a combination of IF and VLOOKUP functions. A formula that will work for Excel 2007 or newer is the following:
=IFERROR(IF(VLOOKUP($A1,Sheet1!$A:$C,2,FALSE)=$B1,VLOOKUP($A1,Sheet1!$A:$C,3,FALSE),0),0)
Older versions of Excel do not support IFERROR, but you can still use a similar approach as explained here.
I have uploaded an example workbook here, which includes an alternative method in column D of Sheet2 as well.

Resources