Sum a cell that contains multiple numbers that represent other values

NateTiberius

New Member
Joined
Sep 12, 2022
Messages
8
Office Version
  1. 2019
Platform
  1. Windows
Hey.

I have hundreds of cells that each contain different number codes that represent another value. For instance, a cell might contain, "4, 16, 32". Each of those distinct numbers correlates to other values. For instance, "4" equals 3.58, 16 equals 2.67, and 32 equals 2.75, etc. What I need is a formula that will read those number codes in the cell and then sum the numbers they represent. So, in the case of the "4, 16, 32" cell, it would sum to 9.00.

So, using the fourth formula listed here – How to use Excel formula: "If cell contains" | SoftwareKeep – I was able to ALMOST make this happen. Below is an example formula:

=IF(OR(ISNUMBER(SEARCH("4",H2))),F5)+IF(OR(ISNUMBER(SEARCH("16",H2))),F17)+IF(OR(ISNUMBER(SEARCH("32",H2))),F33)

Using that formula gets me my number I want for the above example, but there's a problem. There are codes that range from 1 through 38. So one cell might only have a "1", another only a "5", and another a "15". However, using that formula, when it reads a "15", it sees it as not only a "15", but as a "1", a "5", AND a "15". So it adds three numbers together instead of only the 15.

I thought I could "outsmart" that by instead having the formula search for "1," (with a comma). But that does not work because certain cells END in single digit number (or, as mentioned above, ONLY contain a single number): for instance, "15, 6, 1". So using the "1," method, causes the formula not to find that cell-ending "1". Below is the full formula I was using to add all the codes from 1 through 38 (I purposefully left out a couple numbers).

=IF(OR(ISNUMBER(SEARCH("1,",'33122 Raw'!C2))),Key!F2)+IF(OR(ISNUMBER(SEARCH("2,",'33122 Raw'!C2))),Key!F3)+IF(OR(ISNUMBER(SEARCH("3,",'33122 Raw'!C2))),Key!F4)+IF(OR(ISNUMBER(SEARCH("4,",'33122 Raw'!C2))),Key!F5)+IF(OR(ISNUMBER(SEARCH("5,",'33122 Raw'!C2))),Key!F6)+IF(OR(ISNUMBER(SEARCH("6,",'33122 Raw'!C2))),Key!F7)+IF(OR(ISNUMBER(SEARCH("8,",'33122 Raw'!C2))),Key!F9)+IF(OR(ISNUMBER(SEARCH("9,",'33122 Raw'!C2))),Key!F10)+IF(OR(ISNUMBER(SEARCH("10",'33122 Raw'!C2))),Key!F11)+IF(OR(ISNUMBER(SEARCH("11",'33122 Raw'!C2))),Key!F12)+IF(OR(ISNUMBER(SEARCH("12",'33122 Raw'!C2))),Key!F13)+IF(OR(ISNUMBER(SEARCH("13",'33122 Raw'!C2))),Key!F14)+IF(OR(ISNUMBER(SEARCH("14",'33122 Raw'!C2))),Key!F15)+IF(OR(ISNUMBER(SEARCH("15",'33122 Raw'!C2))),Key!F16)+IF(OR(ISNUMBER(SEARCH("16",'33122 Raw'!C2))),Key!F17)+IF(OR(ISNUMBER(SEARCH("17",'33122 Raw'!C2))),Key!F18)+IF(OR(ISNUMBER(SEARCH("18",'33122 Raw'!C2))),Key!F19)+IF(OR(ISNUMBER(SEARCH("19",'33122 Raw'!C2))),Key!F20)+IF(OR(ISNUMBER(SEARCH("20",'33122 Raw'!C2))),Key!F21)+IF(OR(ISNUMBER(SEARCH("21",'33122 Raw'!C2))),Key!F22)+IF(OR(ISNUMBER(SEARCH("22",'33122 Raw'!C2))),Key!F23)+IF(OR(ISNUMBER(SEARCH("23",'33122 Raw'!C2))),Key!F24)+IF(OR(ISNUMBER(SEARCH("27",'33122 Raw'!C2))),Key!F28)+IF(OR(ISNUMBER(SEARCH("28",'33122 Raw'!C2))),Key!F29)+IF(OR(ISNUMBER(SEARCH("30",'33122 Raw'!C2))),Key!F31)+IF(OR(ISNUMBER(SEARCH("30",'33122 Raw'!C2))),Key!F31)+IF(OR(ISNUMBER(SEARCH("31",'33122 Raw'!C2))),Key!F32)+IF(OR(ISNUMBER(SEARCH("32",'33122 Raw'!C2))),Key!F33)+IF(OR(ISNUMBER(SEARCH("33",'33122 Raw'!C2))),Key!F34)+IF(OR(ISNUMBER(SEARCH("34",'33122 Raw'!C2))),Key!F35)+IF(OR(ISNUMBER(SEARCH("35",'33122 Raw'!C2))),Key!F36)+IF(OR(ISNUMBER(SEARCH("36",'33122 Raw'!C2))),Key!F37)+IF(OR(ISNUMBER(SEARCH("38",'33122 Raw'!C2))),Key!F39)

Long story short, does anyone have a formula to accomplish this goal?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I would hate to work with such a long formula. Have you considered using a macro? I can't promise a solution, but if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet, I could have a look at it. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
Can you post some sample data, along with expected results.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.

Also do you have the TEXTSPLIT function yet?
 
Upvote 0
@NateTiberius Might something like below help?

Requires a reference table to define relate the text and sum values.

Book1
ABCDE
1Text #Value TextSum
213.24,16,329.00
323.22,6,349.60
433.2103.20
543.581,106.40
653.210,16.40
763.210,1,49.98
873.27,3,2,812.80
983.2322.75
1093.20.00
11103.2
12113.2
13123.2
14133.2
15143.2
16153.2
17162.67
18173.2
19183.2
20193.2
21203.2
22213.2
23223.2
24233.2
25243.2
26253.2
27263.2
28273.2
29283.2
30293.2
31303.2
32313.2
33322.75
34333.2
35343.2
36353.2
37363.2
38373.2
Sheet2
Cell Formulas
RangeFormula
E2:E10E2=SUM(SUMIF($A$2:$A$39,TEXTSPLIT(D2,","),$B$2:$B$39))
 
Upvote 0
Can you post some sample data, along with expected results.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.

Also do you have the TEXTSPLIT function yet?
I do not have the TEXTSPLIT function yet. Also, below is a minisheet using the XL2BB add-in.

03457816.XLSX
ABCDEFGH
1KEY CODESTotal HoursEmployee1-Jan2-Jan3-Jan4-Jan
213.25A2020
322.75B12, 13, 1612, 1312, 16, 1312, 3, 13
430.50C36, 37, 38 36, 37, 38 36, 37, 38 36, 37, 38
543.58D48, 9, 415, 17
652.00E30, 3230, 32, 16, 1730, 32Vacation
762.00F23,24,25,26,28,2923,24,25,26,28,2923,24,25,26,28,2923,24,25,26,28,29
871.25G5, 225, 6, 1921, 22, 1921, 22, 19
981.75H
1091.25I1820
11101.75J19, 10102, 102, 33
1211K31, 3331, 3331, 3331
13122.50L
14132.50M1818, 20
15141.25N2121, 22
16153.08O15, 3, 615, 315, 38, 9
17162.67P8, 9, 178, 9, 2018, 1730, 32
18172.83Q11, 11, 3511, 11, 3511, 11, 3511, 11, 35, 6
19183.50R2, 425, 6 5, 4
20192.50
21202.00Employee1-Jan2-Jan3-Jan4-Jan
22212.50A2.002.00
23222.50B7.675.007.675.50
24235.50C9.839.839.839.83
2524
2625Above is an example of who they SHOULD sum to (I manually did these)
2726
28271.25
29282.50
3029
31302.25
32313.25
33322.75
34333.58
35343.00
36355.00
37366.08
3837
39383.75
Key
Cell Formulas
RangeFormula
E22E22=B21
F22F22=B21
E23E23=B13+B14+B17
F23F23=B13+B14
G23G23=B13+B17+B14
H23H23=B13+B4+B14
E24:H24E24=$B$37+$B$38+$B$39
 
Upvote 0
@NateTiberius Might something like below help?

Requires a reference table to define relate the text and sum values.

Book1
ABCDE
1Text #Value TextSum
213.24,16,329.00
323.22,6,349.60
433.2103.20
543.581,106.40
653.210,16.40
763.210,1,49.98
873.27,3,2,812.80
983.2322.75
1093.20.00
11103.2
12113.2
13123.2
14133.2
15143.2
16153.2
17162.67
18173.2
19183.2
20193.2
21203.2
22213.2
23223.2
24233.2
25243.2
26253.2
27263.2
28273.2
29283.2
30293.2
31303.2
32313.2
33322.75
34333.2
35343.2
36353.2
37363.2
38373.2
Sheet2
Cell Formulas
RangeFormula
E2:E10E2=SUM(SUMIF($A$2:$A$39,TEXTSPLIT(D2,","),$B$2:$B$39))
I posted a minisheet in my reply above if you'd be kind enough to take a look. Your sheet would work if there weren't multiple values that needed summing in each cell.
 
Upvote 0
Thanks for that.
How about
Fluff.xlsm
ABCDEFGH
1KEY CODESTotal HoursEmployee32874328753287632877
213.25A2020
322.75B12, 13, 1612, 1312, 16, 1312, 3, 13
430.50C36, 37, 38 36, 37, 38 36, 37, 38 36, 37, 38
543.58D48, 9, 415, 17
652.00E30, 3230, 32, 16, 1730, 32Vacation
762.00F23,24,25,26,28,2923,24,25,26,28,2923,24,25,26,28,2923,24,25,26,28,29
871.25G5, 225, 6, 1921, 22, 1921, 22, 19
981.75H
1091.25I1820
11101.75J19, 10102, 102, 33
1211K31, 3331, 3331, 3331
13122.50L
14132.50M1818, 20
15141.25N2121, 22
16153.08O15, 3, 615, 315, 38, 9
17162.67P8, 9, 178, 9, 2018, 1730, 32
18172.83Q11, 11, 3511, 11, 3511, 11, 3511, 11, 35, 6
19183.50R2, 425, 6 5, 4
20192.50
21202.00Employee32874328753287632877
22212.50A2.002.000.000.00
23222.50B7.675.007.675.50
24235.50C9.839.839.839.83
2524D0.003.586.585.92
2625E5.0010.505.000.00
2726F8.008.008.008.00
28271.25G4.506.507.507.50
29282.50H0.000.000.000.00
3029I3.500.002.000.00
31302.25J4.251.754.506.33
32313.25K6.836.836.833.25
33322.75L0.000.000.000.00
34333.58M0.003.500.005.50
35343.00N2.505.000.000.00
36355.00O5.583.583.583.00
37366.08P5.835.006.335.00
3837Q5.005.005.007.00
39383.75R6.332.754.005.58
Data
Cell Formulas
RangeFormula
E22:H39E22=SUM(SUMIFS($B:$B,$A:$A,FILTERXML("<k><m>"&SUBSTITUTE(E2,",","</m><m>")&"</m></k>","//m")))
 
Upvote 0
Thanks for that.
How about
Fluff.xlsm
ABCDEFGH
1KEY CODESTotal HoursEmployee32874328753287632877
213.25A2020
322.75B12, 13, 1612, 1312, 16, 1312, 3, 13
430.50C36, 37, 38 36, 37, 38 36, 37, 38 36, 37, 38
543.58D48, 9, 415, 17
652.00E30, 3230, 32, 16, 1730, 32Vacation
762.00F23,24,25,26,28,2923,24,25,26,28,2923,24,25,26,28,2923,24,25,26,28,29
871.25G5, 225, 6, 1921, 22, 1921, 22, 19
981.75H
1091.25I1820
11101.75J19, 10102, 102, 33
1211K31, 3331, 3331, 3331
13122.50L
14132.50M1818, 20
15141.25N2121, 22
16153.08O15, 3, 615, 315, 38, 9
17162.67P8, 9, 178, 9, 2018, 1730, 32
18172.83Q11, 11, 3511, 11, 3511, 11, 3511, 11, 35, 6
19183.50R2, 425, 6 5, 4
20192.50
21202.00Employee32874328753287632877
22212.50A2.002.000.000.00
23222.50B7.675.007.675.50
24235.50C9.839.839.839.83
2524D0.003.586.585.92
2625E5.0010.505.000.00
2726F8.008.008.008.00
28271.25G4.506.507.507.50
29282.50H0.000.000.000.00
3029I3.500.002.000.00
31302.25J4.251.754.506.33
32313.25K6.836.836.833.25
33322.75L0.000.000.000.00
34333.58M0.003.500.005.50
35343.00N2.505.000.000.00
36355.00O5.583.583.583.00
37366.08P5.835.006.335.00
3837Q5.005.005.007.00
39383.75R6.332.754.005.58
Data
Cell Formulas
RangeFormula
E22:H39E22=SUM(SUMIFS($B:$B,$A:$A,FILTERXML("<k><m>"&SUBSTITUTE(E2,",","</m><m>")&"</m></k>","//m")))
That is beautiful. It works for what I need. Thank you so much! One issue though, when I copied that formula over, it keeps wanting me to manually put each cell as an array. So I'm having to go through each cell and click ctrl-shift-enter. Any idea why it's doing that? Thanks!
 
Upvote 0
What makes you say that?
Because the formula isn't copying to each cell properly. When I go to drag E22, for instance, to the cells below, all it's doing is dragging the "2.0" down (I am making sure the cell it's referencing is appropriate too). Then, when I hit ctrl-shift-enter, it puts it into an array and calculates it properly. But as soon as the array is gone, it goes back to rendering an inaccurate calculation.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top