How to sum a row in Excel with lookup values from a column based lookup? - excel

I have rows of values in columns AC to AU (but also some blanks)
I want to convert these values in a formula via a lookup and sum all the lookup values in a row.
For 1 cell I can use VLOOKUP(AC2,'Lookup_Table'!A2:B41,2) successfully
How do I sum the whole row of AC2 to AU2 with this kind of lookup?
Note the lookup is column oriented in a vertical lookup, the 'Lookup Table' is actually a worksheet.
This has stumped me for hours now!
| AC | AD | AE ..Ax... AU
Row 1 | 12 | 23 | 43 ..00... 67
'Lookup table' worksheet
A | B
12 | 4
23 | 2
43 | 3
67 | 5
The result should be 14 for the sample Row 1 data above

It is much easier to use an array formula (ctrl+shift+enter instead of just enter). Generally I don't like array formulas (because they are easy for the uneducated to break), but I think it will work the best in your situation apart from reformatting your sheet or using helper columns.
{=SUM(IF(AC2:AU2=Lookup_Table!A2:A41,Lookup_Table!B2:B41))}
which should have {} around the whole thing if you entered it correctly.

You need to use a combination of SUM and INDEX functions, where AB in Lookup_Table is your index column for the table, and A! is the value you wish to lookup:
=SUM(INDEX(Lookup_Table!$AC$1,MATCH(A1,Lookup_Table!$AB:$AB,0)):INDEX(Lookup_Table!$AU$1,MATCH(A1,Lookup_Table!$AB:$AB,0)))

Related

IF THEN (sourcing a table on Sheet 2)

I'm looking to create an Excel spreadsheet using what I think is a bit of a complicated IF/THEN. I want to have a table on Sheet 2 that gives a value in one column (e.g., Column A: Between 5 and 5.5), and another value in Column B (e.g., A-).
On Sheet 1, I will have a column (e.g., F) that has the number that should fall somewhere within Column A. I would like to automatically update Column I with the value that is in Column B on Sheet 2.
So I want to have a formula in cells in Column I that looks at the value in Column F (and refers to the relationship between these values in Columns A & B in Sheet 2).
Is this doable?
The table in Sheet 2 would be:
15 | A+
14 | A
13 | A-
12 | B+
11 | B
10 | B-
09 | C+
08 | C
07 | C-
06 | D+
05 | D
04 | D-
03 | E+
02 | E
01 | E-
Using nested IFs is a horrible idea, you should consider using a lookup table instead.
The last parameter of VLOOKUP is probably what you are looking for. Setting it to true makes the function looks for approximate match instead of exact match.
You will need sort your table in ascending order (i.e. from 1(E-) to 15(1+)).
=LOOKUP(F1,Sheet2!A1:A3,Sheet2!B1:B3)
Try this Code put in the Sheet 1. Column I
If you are using Excel 365, you can use the new IFS statement.
=IFS(A1<=1,"E-",A1<=2,"E",A1<=3,"E+",A1<=4,"D-",A1<=5,"D",A1<=6,"D+",A1<=7,"C-",A1<=8,"C",A1<=9,"C+",A1<=10,"B-",A1<=11,"B",A1<=12,"B+",A1<=13,"A-",A1<=14,"A",A1<=15,"A+")
That said, since you already have a table on your second sheet, I would highly recommend using an INDEX/MATCH method as suggested by #Michal Rosa

Excel function for comparing columns with repeated values

I'm using excel and have two columns (A & B) with values
I want to search for each value in Column A and return the position in Column B.
I'm using this formula:
IFERROR(MATCH("Values in Column A";"Array = Column B";0);0)
The results are:
Column A | Column B | Column C
1 | 4 | 2
2 | 1 | 3
3 | 2 | 4
4 | 1 | 1
1 | 2 | 2
| 3 |
It works fine if it doesn't encounter repeated values. However, I want it to encounter repeated values, so the formula should ignore the ones it was encountered before and go through the others. So the correct result should look like this:
Column C
2
3
5
1
4
Can you help me on this? Is there a VBA routine for this?
From the article Getting the 2nd matching value from a list using VLOOKUP formula, you can create a helper column to affix the instance number of each value, to create unique id's.
For example, in Column C, add the following function:
=A1&"-"&COUNTIF($A$1:A1,A1)
Note: The relative reference on the count range will cause the applicable range to grow as it is dragged down. The count of the items matching that cell in a range containing only that cell should always be one. As it gets dragged down to include other cells, it will increment accordingly.
Then add the same thing in Column D to get the instances of cells in Column B:
=B1&"-"&COUNTIF($B$1:B1,B1)
Finally, do the math you want to do in Column E like this:
=IFERROR(MATCH(C1,D:D,0),0)

Excel SUMIF column value matches

I would like to sum all values in column J when the value in column K matches. So, for example, I have the following:
COL J | COL K
25.00 | Now
45.00 | Aug 15
40.00 | Sep 10
70.00 | Now
14.00 | Aug 15
92.00 | Now
I'd like Excel to find all matching values in Column K and add up the values in corresponding rows of column J. For the example above it would sum 25.00, 70.00 and 92.00 which correspond with "Now" and then also add up 45.00 and 14.00 which correspond with Aug 15.
I know it can be done with formulas like this:
=SUMIF(K:K,"Now",J:J)
=SUMIF(K:K,"Aug 15",J:J)
However, I'd like to be more flexible and not have to have a separate formula for every different value in Column K. Is there a way to use a wildcard of some sort that can replace "Now" and "Aug 15" in the example above so that I could just have one formula that finds any matches in Column K and sums the corresponding values for those rows in Column J?
Thank you!
SUMIF accepts wildcards (e.g., this or this).
I tried adding another line to your data,
92.00 | Never
and then =SUMIF(K:K,"N*",J:J). It works great. If I understood what you were specifically aiming at, it would be =SUMIF(K:K,"*",J:J).
PS: I wouldn't know how it behaves when you have cells formatted as date, and you try to match according to what is displayed. That might involve locale issues.
You need to investigate Array Formulas also known as CSE formulas. http://www.mrexcel.com/articles/CSE-array-formulas-excel.php or http://office.microsoft.com/en-us/excel-help/guidelines-and-examples-of-array-formulas-HA010342564.aspx
=SUM(IF($K$1:$K$6=K1,$J$1:$J$6,0))
If you paste this formula into cell L1 (assuming your data is in K1:J6) and press Control-Shift-Enter to save it, it will calculate the sum of all the cells in Column J that have a matching Column K. Array Formulas are pretty powerful but they are pretty hard to debug.

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.

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