Excel SUMIF based on array using text string - excel-formula

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}

Related

Excel MERGE two tables

I have SET 1
CLASS
Student
TEST
SCORE
A
1
1
46
A
1
2
50
A
1
3
45
A
2
1
45
A
2
2
47
A
2
3
31
A
3
1
34
A
3
2
45
B
1
1
36
B
2
1
31
B
2
2
41
B
3
1
50
C
1
1
42
C
3
1
31
and SET 2
CLASS
SIZE
YEARS
A
39
7
B
20
12
C
31
6
and wish to COMBINE to make SET 3
CLASS
STUDENT
TEST
SCORE
SIZE
YEARS
A
1
1
46
39
7
A
1
2
50
39
7
A
1
3
45
39
7
A
2
1
45
39
7
A
2
2
47
39
7
A
2
3
31
39
7
A
3
1
34
39
7
A
3
2
45
39
7
B
1
1
36
20
12
B
2
1
31
20
12
B
2
2
41
20
12
B
3
1
50
20
12
C
1
1
42
31
6
C
3
1
31
31
6
so basically add the SIZE and YEARS columns from SET 2 and merge on CLASS onto SET 1. In excel how you can do this? I need to match on CLASS
Define both sets as tables and “left join” in PowerQuery. There you can choose the columns of the resulting table.
https://learn.microsoft.com/en-us/power-query/merge-queries-left-outer
If you have Set 1 on the top left of a worksheet "Set1" and Set 2 on the top left of a worksheet "Set2", then you can use the formula
=VLOOKUP(A2;'Set2'!$A$2:$C$4;2;FALSE), where $A$2:$C$4 is the range of Set2, and A2 is the class value from Set1, which is what is used to do the lookup in Set2. The next argument, 2, means to take the second row from Set2, and the FALSE at the end means that you only want exact matches on the CLASS. You can do auto-fill with this formula, and do similar steps for the years. If you look up the help for VLOOKUP within Excel, that should help you to understand how it works.
Your first set of data is essentially your primary set of data that you just want to add attribute columns to. I built this example on Google Sheets which should help explain. Using spill formulas, only a few cells are needed with their own formulas. You can see them as they are highlighted in yellow. When you use in Excel, obviously make sure you change the column references, but this would get you the answer.
Note you have to have SpillRange in Excel for this to work. To test, see if you have the formula =unique()
This solution may work for you if both sets start in the same column. As example in my image, both of them start at column A. You can get all data with a single VLOOKUP formula:
Formula in cell E2 is:
=VLOOKUP($A2;$A$22:$R$25;COLUMN($B22);FALSE)
Notice the mixed references at first and third argument and absolute references in the second one. Third argument is critical, because is the relational position between both sets, that's the reason it's easier if both sets start at same column. If not, you'll need to adjust this argument substracting or adding, depending on the case.
Anyways, with a single formula, you can get any number of columns. The only disavantage of this formula is that you need to manually drag to right until you got all the columns (10, 30 or whatever). You'll notice you are done because the formula will raise an error:
This error means you are trying to get a referenced outside of your column area.

Excel macro replace cell in A by other cell in B

I have a excel document where I have something like this
A B C
1 1 45 a
2 2 32 b
3 3 34 H
4 3 37
5 4 49 i
5 5 76 H
Note that 3c is combined but 3b isn't.
I need to do a macro to change the content of B with the content of C but only those that don't have a letter H. so the document would look like this
A B C
1 1 a a
2 2 b b
3 3 34 H
4 3 37
5 4 i i
5 5 76 H
Here a image
Just use this simple formula in column C,
=IF(B1="H",A1,B1)
and drag it throughout the range. Once done, copy paste all of the data in column C to A (paste special)

Formula to add text based on values of two other cells

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)),"")

Excel table formulas to return blank

I have a table in excel with 2 columns, the E column is the running total the D column is the input value so normally it would be = E15+D16 however, i want the E column to return a blank if nothing is entered in the D column- what formula do I need?
1 Nov-23 Nov-30 1,230 1,230
2 Dec-01 Dec-07 130 1,360
3 Dec-08 Dec-14 416 1,776
4 Dec-15 Dec-21 124 1,900
5 Dec-22 Dec-28 102 2,002
6 Dec-29 Jan-04 83 2,085
7 Jan-05 Jan-11 95 2,180
8 Jan-12 Jan-18 88 2,268
9 Jan-19 Jan-25 102 2,370
10 Jan-26 Feb-01 130 2,500
11 Feb-02 Feb-08 311 2,811
12 Feb-09 Feb-15
13
14
15
16
17
18
19
20
21
22
=if(D16="","",E15+D16)
You dont even need the ISBLANK, just use empty quotes.
ISBLANK is what you're looking for.
In E16 =IF(ISBLANK(D16), "", E15+D16)
Use If and IsBlank in conjunction.
Do a check to see if the cell is blank, then depending on the result do the sum or the return blank. I don't have excel in front of me atm, but it should go something like this:
=if(ISBLANK(D16), "", E15+D16)
You can drag this down starting from the second cell in the column where this running total lives. The first one is obviously just the value from the adjacent cell.

divide data in one column into more column in excel

i want to do this in Microsoft Excel 2007
This a one column. I have 20098 data in one column like below.
1
2
3
4
5
6
7
8
131
1
31
31
31
31
41
I want to rearrange those data like this how can i do it
1 4 7 1 31
2 5 8 31 31
3 6 131 31 41
If your data was in column A then in cell B1 put
=OFFSET($A1,3*(COLUMN()-COLUMN($B$1)),)
and copy down and right to split your data as desired
use this formula in all 3 rows and 6700 columns of the resulting range:
=INDEX($A:$A;(COLUMN()-first_column)*3 + ROW()-first_row+1)
where first_column is =column(..) and first_row is =row(..) of the cell where you want to have the 1st value
e.g. if you use B1:IWS3 range to list the results, the formula will be:
=INDEX($A:$A;(COLUMN()-2)*3 + ROW())

Resources