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

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

Related

Using SUMIF on a range of columns or SUMPRODUCT to ignore text items

I have a range with various text and numbers in them. I wish to total the numbers based on the identifying first column.
I have tried
=SUMIF(A1:A20,"John",B1:E20)
which only returns the first columns number. I've also tried
=SUMPRODUCT((A1:A20="John")*(B1:E20))
but as there is text in column C, it returns #VALUE!.
A | B | C | D | E
John | 5 | Wine | 2 | 7
Sean | 6 | Beer | 5 | 2
I want all of the numeric values in columns B-E to be totalled together when "John" is in column A
Here is an array formula solution - use Ctrl, Shift and Enter to confirm:
=SUM(IF(A1:A20="John",IF(ISNUMBER(B1:E20),B1:E20)))
If you just want to exclude column C you could use this non-array formula:
=SUMPRODUCT((A1:A20="John")*(B1:B20))+SUMPRODUCT((A1:A20="John")*(D1:E20))
Alternatively, perhaps move C so it's not in the middle of your numbers.
Try this formula:
=IF(A1="John", SUMPRODUCT(--(ISNUMBER(B1:E1)),B1:E1), "")
and drag down to get sum on each row.

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

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

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

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

Find two matching rows and display data from the thirt one (Excel)

So i have Two Sheets.
First sheet contains two columns
BRAND | LEFTOVER
The second sheet consists of two columns also.
BRAND | LEFTOVER (%)
So in case if the BRAND row value in the first Sheet will match the BRAND row value in the second i want to display the matching LEFTOVER (%) row value in the first sheet rows in the column LEFTOVER.
Kind of lost here.
Appreciate any ideas. Thanks.
In Sheet2:
. A | B
--------------------
1 BRAND | LEFTOVER %
2 X | Y
3 |
In Sheet1:
. A | B
--------------------
1 BRAND | LEFTOVER
2 X | =VLOOKUP(A2,Sheet2!A:B,2)
3 |
The VLookup function searches for its first parameter (in this case the value of Sheet1!A2) in the first column of the range denoted by the second parameter (in this case the leftmost column of the range containing columns A and B on Sheet2)
It then returns the value from that same row of the range that is to the right in the columns denoted by the third parameter (1 is the leftmost column where the matched value was). So in this case we use the number 2 because 1 means column A and 2 is column B (which explains why we used a two column wide range for the second parameter - it needed to encompass the column the result was in)
This isn't the only way to do this, but it is the easiest.
As Jerry stated VLOOKUP is the simplest way to do this.
HOWEVER if you have multiple/repeat instances (rows) in BRAND, VLOOKUP will only return the first record (row) that appears in your data.
If this is the case, you will need to add either a unique identifier column; and/or additional criteria to differentiate between the repeat instances.
As an example column A is used as a unique identifier to differentiate between the 2 'Nike' rows.
A B C
1 BRAND LEFTOVER
2 Nike 50
3 Adidas 25
4 Reebok 30
5 Nike 29
I feel that you can use vlookup to accomplish your goals.
Let me explain it in a bit detail.Suppose you have two sheets as:
A | B | A | B
--------------------- | -------------------
1 BRAND | LEFTOVER % | 1 BRAND | LEFTOVER
2 X | Y | 2 X | =Vlookup(A2,Sheet2!A:B,False)
3 | | 3 |
Sheet2 | Sheet1
After this you can drag this formula for the entire range. This will automatically make the formula correct for the below cells as well.
Also, if you need to populate any other fields from the Sheet2 then you can also use the vlookup as an array formula like: VLOOKUP(A2,Sheet2!A:B,{1,2,3,4},FALSE)
Enter this as an array formula using Crtl+Shift+Enter
Here {1,2,3,4} stands for the columns to be fetched.
If you want to know more about vlookup then read this article: http://www.exceltrick.com/formulas_macros/vlookup-in-excel

Resources