Related
I am trying to use the IF and AND function in excel for values in two different cells. I have 25 conditions.
Below is the formula I've created but it keeps on saying there's an error.
IF(AND(A10=“A”,B10=1),11,IF(AND(A=“A”,B10=2),16,IF(AND(A10=“A”,B10=3),20,IF(AND(A10=“A”,B10=4),23,IF(AND(A10=“A”,B10=5),25,IF(AND(A10=“B”,B10=1),7,IF(AND(A10=“B”,B10=2),12,IF(AND(A10=“B”,B10=3),17,IF(AND(A10=“B”,B10=4),21,IF(AND(A10=“B”,B10=5),24,IF(AND(A10=“C”,B10=1),4,IF(AND(A10=“C”,B10=2),8,IF(AND(A10=“C”,B10=3),13,IF(AND(A10=“C”,B10=4),18,IF(AND(A10=“C”,B10=5),22,IF(AND(A10=“D”,B10=1),2,IF(AND(A10=“D”,B10=2),5,IF(AND(A10=“D”,B10=3),9,IF(AND(A10=“D”,B10=4),14,IF(AND(A10=“D”,B10=5),19,IF(AND(A10=“E”,B10=1),1,IF(AND(A10=“E”,B10=2),3,IF(AND(A10=“E”,B10=3),6,IF(AND(A10=“E”,B10=4),10,15))))))))))))))))))))))))))))))))))))))))))))))))
I expected the output to be, for example; if cell1 is "A" and cell2 is 1 the result should be 11.
I would highly advise a lookup table. Simply have all of your options listed out with their desired results and find them with a criteria search, such as the use of sumifs function.
For example, if you paste J1:L25 your possibilities:
A 1 11
A 2 16
A 3 20
A 4 23
A 5 25
B 1 7
B 2 12
B 3 17
B 4 21
B 5 24
C 1 4
C 2 8
C 3 13
C 4 18
C 5 22
D 1 2
D 2 5
D 3 9
D 4 14
D 5 19
E 1 1
E 2 3
E 3 6
E 4 10
E 5 15
You can then place the formula =SUMIFS($L$1:$L$25,$J$1:$J$25,$A$10,$K$1:$K$25,$B$10) to return your desired value.
That is, =SUMIFS(range_of_results, criteria_range_of_A-E, A10, criteria_range_of_1-5, B10)
Excel formula - If A=1 B=2.......Z=26. If you input CAT in cell it should display the result 24 ie C+A+T. Not VB or JAVA or any programming language just the excel formula.
This is what I tried
=SUM(LOOKUP({"C","A","T"},B3:B28,C3:C28))
with input of below in the cells B3:B28,C3:C28. I want the result to display when I put in CAT in the cell.
A 1
B 2
C 3
D 4
E 5
F 6
G 7
H 8
I 9
J 10
K 11
L 12
M 13
N 14
O 15
P 16
Q 17
R 18
S 19
T 20
U 21
V 22
W 23
X 24
Y 25
Z 26
Use SUMPRODUCT to iterate the letters and use CODE to return the value:
=SUMPRODUCT(CODE(UPPER(MID(A1,ROW($XFD$1:INDEX($XFD:$XFD,LEN(A1))),1)))-64)
I have two tables of data with the same columns. The first is populated with experimental data:
`Treatment Species TimeofDay Temp Light X
M B AM 25 25 2
M B PM 26 50 3
M B PM 27 150 4
M C AM 25 25 5
M C AM 26 150 6
M C PM 27 500 7
M C PM 28 800 9
A B AM 25 25 2
A B PM 26 50 3
A B PM 27 150 4
A C AM 25 25 5
A C AM 26 150 6
A C PM 27 500 7
A C PM 28 800 9
In the second table I want to fill in the "X" column with values from the first table so that in the given row A) all of the categorical values match exactly those from table one AND B) Temp and Light values are closest (but won't be exact) to matching values in table 1.
For example, if in Table 2 I have:
Treatment Species TimeofDay Temp Light X
M B PM 30 200
I would want the function to give me 4 in the X column.
I am familiar with indexing a value in one column given a match in another and with finding a closest matching value in a column, but I am having trouble putting all these criteria together:
=INDEX(Table1!F$2:F$20,
MATCH(Table2!A$2,Table1!A$2:A$20,0))
MATCH(Table2!B$2,Table1!B$2:B$20,0))
MATCH(Table2!C$2,Table1!C$2:C$20,0))
MATCH(MIN(ABS(Table1!D$2:D$20-Table2!D$2)),ABS(Table1!D$2:D$20-Table2!D$2), 0))
MATCH(MIN(ABS(Table1!E$2:E$20-Table2!E$2)),ABS(Table1!E$2:E$20-Table2!E$2),0))
Thank you in advance for your help.
This formula is working, put in F2:
=INDEX(Table1!F:F,MATCH(MIN(IF(A2=Table1!A:A,IF(B2 = Table1!B:B,IF(C2 = Table1!C:C,ABS((Table1!D:D+Table1!E:E)-(D2+E2)))))),IF(A2=Table1!A:A,IF(B2 = Table1!B:B,IF(C2 = Table1!C:C,ABS((Table1!D:D+Table1!E:E)-(D2+E2))))),0))
This is an array formula and must be confirmed with Ctrl-Shift-Enter when exiting edit mode. Then copy down.
As to your other comment the priority if the difference is the same will be the first in order.
I have a large spreadsheet that needs a bit of fine-tuning. Column A contains numbers from 1-4000, sequentially-listed. Column B contains some of those same numbers, but many numbers are skipped (for example: 1, 5, 6, 7, 11, 12, 25...); those numbers are not "spaced out" relative to the numbers in column A. Column C contains text entries related to the Column B values. I need to add a formula in column D that will evaluate whether the number in A1 (for example) matches the number in B1, and if it does match it should place the value of C1 in D1. Likewise, if A2 matches B2, then the value of C2 should be placed in D1.
I tried writing some formulas similar to this, but they become far too large when you have to take into account every cell combination: =IF(A1=E1,F1). If I can just get the column B cells to "space themselves out" so that they match up with the cells in column A, that would get me where I need to be. Of course, the Column C data values would need to "follow along" with the Column B values when they are spaced out.
Any ideas on how I can make this happen?
If the data is like this:
A B C
---------------
1 1 Red
2 5 Blue
3 6 Red
4 7 Yellow
5 11 Black
6 12 Green
7 25 Yellow
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
And the desired result is this:
A B C D
--------------------
1 1 Red Red
2 5 Blue
3 6 Red
4 7 Yellow
5 11 Black Blue
6 12 Green Red
7 25 Yellow Yellow
8
9
10
11 Black
12 Green
13
14
15
16
17
18
19
20
21
22
23
24
25 Yellow
We can accomplish that using an INDEX-MATCH based formula starting in D1 and auto filling down:
=IFERROR(INDEX(C:C,MATCH(A1,B:B,0)),"")
It will look like this:
A B C D
-----------------------------------------------------------
1 1 Red =IFERROR(INDEX(C:C,MATCH(A1,B:B,0)),"")
2 5 Blue =IFERROR(INDEX(C:C,MATCH(A2,B:B,0)),"")
3 6 Red =IFERROR(INDEX(C:C,MATCH(A3,B:B,0)),"")
4 7 Yellow =IFERROR(INDEX(C:C,MATCH(A4,B:B,0)),"")
5 11 Black =IFERROR(INDEX(C:C,MATCH(A5,B:B,0)),"")
6 12 Green =IFERROR(INDEX(C:C,MATCH(A6,B:B,0)),"")
7 25 Yellow =IFERROR(INDEX(C:C,MATCH(A7,B:B,0)),"")
8 =IFERROR(INDEX(C:C,MATCH(A8,B:B,0)),"")
9 =IFERROR(INDEX(C:C,MATCH(A9,B:B,0)),"")
10 =IFERROR(INDEX(C:C,MATCH(A10,B:B,0)),"")
11 =IFERROR(INDEX(C:C,MATCH(A11,B:B,0)),"")
12 =IFERROR(INDEX(C:C,MATCH(A12,B:B,0)),"")
13 =IFERROR(INDEX(C:C,MATCH(A13,B:B,0)),"")
14 =IFERROR(INDEX(C:C,MATCH(A14,B:B,0)),"")
15 =IFERROR(INDEX(C:C,MATCH(A15,B:B,0)),"")
16 =IFERROR(INDEX(C:C,MATCH(A16,B:B,0)),"")
17 =IFERROR(INDEX(C:C,MATCH(A17,B:B,0)),"")
18 =IFERROR(INDEX(C:C,MATCH(A18,B:B,0)),"")
19 =IFERROR(INDEX(C:C,MATCH(A19,B:B,0)),"")
20 =IFERROR(INDEX(C:C,MATCH(A20,B:B,0)),"")
21 =IFERROR(INDEX(C:C,MATCH(A21,B:B,0)),"")
22 =IFERROR(INDEX(C:C,MATCH(A22,B:B,0)),"")
23 =IFERROR(INDEX(C:C,MATCH(A23,B:B,0)),"")
24 =IFERROR(INDEX(C:C,MATCH(A24,B:B,0)),"")
25 =IFERROR(INDEX(C:C,MATCH(A25,B:B,0)),"")
Is there a way to substitute the cell address containing a text string as the array criteria in the following formula?
=SUM(SUMIF(A5:A10,{1,22,3},E5:E10))
So instead of {1,22,3}, "1, 22, 3" is entered in cell A2 the formula becomes
=SUM(SUMIF(A5:A10,A2,E5:E10))
I have tried but get 0 as a result (refer C16)
A B C D E F G H
1 Tree
2 {1,22,3} 1
3 22
4 Tree Profit 3
5 1 105
6 2 96
7 1 105
8 1 75
9 2 76.8
10 1 45
11
12 330 =SUM(SUMIF(A5:A10,{1,22,3},B5:B10))
13
14 330 =SUMPRODUCT(SUMIF(A5:A10,E2:E3,B5:B10))
15
16 0 =SUM(SUMIF(A5:A10,A2,B5:B10))
17 NB: Custom Format "{"#"}" on Cell A2 I enter 1,22,3 so it displays {1,22,3}
Ok so after some further searching (see Excel string to criteria) and trial and error I have come up with the following solution.
Using Name Manager I created UDF called GetList which Refers to:
=EVALUATE(Sheet1!$A$3) NB: Cell A3 has this formula in it =TEXT(A2,"{#}")
I then used the following formula:
=SUMPRODUCT(SUMIF($A$5:$A$12,GetList,$B$5:$B$12))
which gives the desired result of 321 as per the other two formulas (see D12 below).
If anyone can suggest a better solution then feel free to do so.
Thanks to Dennis to my original post regarding table
A B C D E
1 Tree
2 1,22,3 1
3 {1,22,3} =TEXT(A2,"{#}") 22
4 Tree Profit 3
5 11 105
6 22 96
7 1 105
8 3 75
9 2 76.8
10 1 45
11
12 321 =SUMPRODUCT(SUMIF($A$5:$A$12,GetList,$B$5:$B$12))
13
14 321 =SUM(SUMIF(A5:A10,{1,22,3},B5:B10))
15
16 321 =SUMPRODUCT(SUMIF(A5:A10,E2:E3,B5:B10))
17
18 0 =SUM(SUMIF(A5:A10,A2,B5:B10))
19 NB: Custom Format "{"#"}" on Cell A2 I enter 1,22,3 so it displays {1,22,3}