Dynamically set cell values from table in Excel - excel

I've got an excel document that essentially looks like this (imagine it having around 15 000 rows):
A B C D E F
---------------------------
Art Price Art Price
---------------------------
A 1 A 5
A 3 B 10
A 4 C 8
B 7
B 2
C 3
C 15
As you can see the prices in column B are inconsistent.
What I want to do is to set the prices (in column B) to the correct prices (that are found in column E) based on the articles name (found in column A and D).
Unfortunately I'm at loss when it comes to VBA in Excel, and formulas in Excel, what would be a smart way to approach (or solve) this?
Thank you in advance!

Try the VLOOKUP excel formula in the excel help, no coding needed.
Enter =VLOOKUP(A2;$D$2:$E$4;2) in cell B2 and fill down.

Related

Counting unique values based on partial text

I've got many items in boxes on a pallet. I would like to know how I can count the unique number of boxes in a pallet.
A
B
C
D
E
1
Item
Pallet-box ID
Pallet No.
No. of boxes
2
abc
P01-B01
P01
5
3
def
P01-B01
P02
2
4
ghi
P01-B02
5
jkl
P01-B02
6
mno
P01-B02
7
pqr
P01-B03
8
stu
P01-B03
9
vwx
P01-B04
10
yz
P01-B05
11
123
P02-B01
12
456
P02-B02
12
789
P02-B02
So, based on the above example, the above pallet (P01) has 5 unique boxes (B01-B05) and pallet (P02) has 2 unique boxes (B01-B02). What kind of formula should I use to achieve the result of 5 for P01 and 2 for P02 in column E? I was thinking of using COUNTIF but it doesn't seem to be applicable here. Any advice/help is greatly appreciated.
If you have Excel 365 you can use the following formulas.
I added some helper columns to achieve the result.
=UNIQUE(tblData[Pallet-box ID]) retrieves the unique Pallet boxes (column E)
Based on that =UNIQUE(LEFT(UNIQUE(tblData[Pallet-box ID]),3)) retrieves the unique pallet no. (column G)
And now we can count the pallet no within the pallet boxes: =COUNTIF(E4#,G4# & "*") (column H)
I'm not a specialist myself, but I have just created following example:
A B C D E
7 a
8 a
9 a
10 b
11 b
In a cell, I created the formula =UNIQUE(E7:E11) and next to it the formula =COUNTIF(E7:E11,UNIQUE(E7:E11)), these are the results:
a 3
b 2
So, combining COUNTIF() and UNIQUE() basic Excel functions might help you.
Edit: you might use a helper column, based on =LEFT(B1,LEN(A1)): I had put P01 in cell "A1" and P02-B01 in cell "B1" and the result was P02, the left side of P02-B01, based on the length of P01.
Well, if you are using either Excel 2021 or O365, then you may try in this way as well,
Unique Pallet No.
• Formula used in cell D3
=UNIQUE(LEFT(Pallet_box_ID,3))
No. Of Boxes
• Formula used in cell E3
=SUMPRODUCT(--(LEFT(UNIQUE(Pallet_box_ID),3)=D3))
Where Pallet_box_ID refers to the range
=$B$3:$B$14
Created using defined name manager --> select the range from B2:B14 & Press CTRL + SHIFT + F3 --> Check Top Row from Create Names From Selection Dialog Box and Press Ok, now you can refer the Name Box showing the range B3:B14 as Pallet_box_ID
Also I will suggest you to use this way because it may happen the Pallet Box ID can be PO10 or PO100 then LEFT(Pallet_box_ID,3) shall not give you proper output as shown in image below
• Formula used in cell D3
=UNIQUE(LEFT(Pallet_box_ID,FIND("-",Pallet_box_ID)-1))
• Formula used in cell E3
=SUMPRODUCT(--(LEFT(UNIQUE(Pallet_box_ID),FIND("-",UNIQUE(Pallet_box_ID))-1)=D3))

Sum values using lookup table, where lookup values are a list of values with comma delimiter

I am trying to sum values based that equal a lookup value. However, that value is actually a list of values delimited by a comma. Below is an example of what I mean.
Suppose I have raw data in the form of sheet1 below:
Sheet1:
A
B
1
ID
VALUE
2
A
30
3
A
50
4
A
20
5
B
10
6
B
20
7
C
70
8
C
40
9
D
30
10
E
50
11
F
20
12
F
30
13
G
10
And I have a look table that groups all IDs by their respective teams, as per sheet2 below.
Sheet2:
A
B
1
TEAM
IDS
2
Red
A, B
3
Blue
C, D
4
Green
E, F, G
And I want to create a report where the user can select the team name, and the sum of the values in sheet1 will aggregate based on the selection, as per the following example. So the user would select "Green" in cell B1 and it would return the sum of values that correspond to E, F, and G in sheet1.
Report:
A
B
1
Select Team:
Green
2
Sum:
110
I have searched all over for a solution to this and was able to find something similar. I tried to repurpose the formula for my data but couldn't get it to work because I think that solution dealt with numbers rather than text.
Excel: Perform a SUMIF where the criteria is a comma-delimited list
Any suggestions would be greatly appreciated!
Edit: Just want to add that I realize I could first parse out the IDs in sheet2, however I'm looking for a formula that can bypass that as my real dataset is quite large and parsing out the IDs under each team would explode the number of rows.
A variation of #JvdV solution on the linked question:
=SUMPRODUCT(SUMIFS(Sheet1!B:B,Sheet1!A:A,FILTERXML("<t><s>"&SUBSTITUTE(VLOOKUP(Sheet2!F1,Sheet2!A:B,2,FALSE),",","</s><s>")&"</s></t>","//s")))
Note, this only works with Excel 2013 or later and only on PC. FILTERXML is not available on Mac or prior to 2013.
If Mac or prior to 2013:
=SUMPRODUCT(SUMIFS(Sheet1!B:B,Sheet1!A:A,TRIM(MID(SUBSTITUTE(VLOOKUP(F1,Sheet2!A:B,2,FALSE),",",REPT(" ",999)),(ROW($ZY1:INDEX($ZY:$ZY,LEN(VLOOKUP(F1,Sheet2!A:B,2,FALSE))-LEN(SUBSTITUTE(VLOOKUP(F1,Sheet2!A:B,2,FALSE),",",""))+1))-1)*999+1,999))))

Return Multiple Unique Matches in Excel without Array Formula

Given an Excel table of shape
Col. A Col B Col. C Col. D Col. E
x 2 x 2 3
x 3 y 7
y 7 z -5
x 2
z -5
I want to return the first unique hit in Column B for argument "x" in Column D,
the second unique hit in Column B for argument "x" in Column E and so forth.
The formula I'm currently using in cell D1 for this is
{=IFERROR(INDEX($B$1:$B$5,MATCH(0,COUNTIF($C1:C1,$B$1:$B$5)+($A$1:$A$5<>$C1),0)),"")}
which is working.
The problem I'm having is that since this is an array formula and since I'm analyzing a decent amount of data computation time for my sheet is too high.
Is there an alternative for this functionality avoiding an array formula?
Thanks!
Haven't got time to test this properly, but if you have Excel 365 you can use a single formula per row and it may be faster:
=TRANSPOSE(UNIQUE(FILTER(B1:B10,A1:A10=C1)))
in D1.
EDIT
To pull the formula down, you need static references as OP has pointed out. Probably should check for empty cells in column C as well, so formula becomes:
=IF(C1="","",TRANSPOSE(UNIQUE(FILTER(B$1:B$10,A$1:A$10=C1))))

Ignore text values in subtotal function

Excel-Sheet:
A B C D E
1 1.200
2 Product A 500
3 Product B 400
4 Product C OK
5 Product D #NA
6 Product E 300
7
8
In the above table I have list of products in Column A and some data about the products in Column B.
In Cell B1 I want to calculated the subtotal of Column B using =SUBTOTAL(9,B2:B6).
However, now I have the issue that Column B not only consists of numbers.
It can also have the data type text (OK, NA). Therefore, the result in Cell B1 currently is #NA.
Is there any kind of formula that I could use so only the number data is considered and the result is 1.200 as in the table above?
Please note:
This function =AGGREGATE(9,6,B2:B6) won't help me because I want to filter the list later on so I need to go with the SUBTOTAL.
Use 7 as the second criterion in AGGREGATE instead of 6 as it will also exclude hidden rows:
=AGGREGATE(9,7,B2:B6)
You can solve this, combining the Excel worksheet functions =Value() and =IfERROR():
The function =Value() gives the value of a number, and in case of text it gives an error.
=IfError() can be used to give 0 in that case.
So, imagine you have following situation:
Column A Column B Column C
1 =Value(A1) =IfError(B1;0)
3.5 =Value(A2) =IfError(B2;0)
AB =Value(A3) =IfError(B3;0)
abc10 =Value(A4) =IfError(B4;0)
This gives following results:
Column A Column B Column C
1 1 1
3.5 3.5 3.5
AB #Value 0
abc10 #Value 0
You can simply take the sum of column C.
So this is based on the summary in B1.
=SUM(IF(ISERROR(B2:B6),"",B2:B6))
You need to push Ctrl+Shft+Enter for this to work.
Hope it helps.

Excel lookup query

I'm not all that with excel and this is driving me nuts. I have a table with 3 columns A B C.
A has up to 150 names.
B has their chosen number from 0-9.
C has 5 random numbers entered from 0-9.
After the numbers have been entered in C, I need to find who in A has a match to the numbers in C and how many times.
I.E:
Bill 7
Mary 4
in C-- 2 7 5 4 4
Results need to show (could be on another sheet):
Bill 1
Mary 2
have spent hours googling, but either can't find help, or I'm too stupid to see it.
You can use COUNTIF to do that.
You can copy/paste to get the name list to the other sheet first.
Then, use:
=COUNTIF(Sheet1!C:C, VLOOKUP(A1, Sheet1!A:B, 2, 0)))
Or if you are able to copy both columns A and B into Sheet2,
=COUNTIF(Sheet1!C:C, B1)
Then copy/paste as values and last delete column B.
If it can be done on the same sheet, you can consider:
=COUNTIF($C$1:$C$5, B1)

Resources