Take a text string from a cell and add them together to get a single value

standardexceluser

New Member
Joined
Jun 7, 2017
Messages
4
in excel i have a vba code that gives values in cell H9 as a string in the following format: "2709.504, 10012.464, 16052.4" and i want to be able to in the cell over (I9) preform =2709.504+ 10012.464+16052.4. and give 28744.368.

how would i be able to do this in excel or vba.

thanks
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try :-
Code:
[COLOR="Navy"]Sub[/COLOR] MG07Jun35
[I9] = Evaluate(Replace([H9], ",", "+"))
 '[COLOR="Green"][B]Or[/B][/COLOR]
 [I9].Formula = "=" & (Replace([H9], ",", "+")) & ""
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
 
Last edited:
Upvote 0
Formula solution but it's fugly:


Book1
HI
92709.504, 10012.464, 16052.428774.37
101, 2, 3, 4, 5, 6, 7, 8, 945
111.2, 1.83
Sheet1
Cell Formulas
RangeFormula
I9{=SUM(TRIM(MID(SUBSTITUTE(H9,", ",REPT(" ",LEN(H9))), (ROW(OFFSET($A$1,0,0,(LEN(H9)-LEN(SUBSTITUTE(H9,", ","")))/2+1))-1)*LEN(H9)+1, LEN(H9)))+0)}
Press CTRL+SHIFT+ENTER to enter array formulas.


WBD
 
Upvote 0
Although it does beg the question that if you're VBA is generating this in H9, why not just adapt that code to add up the values and put it in I9?

WBD
 
Upvote 0
i tried putting in your excel code and it only gave the first value of the string, (2709.504). and the values and the amount of numbers in h9 can change after every run of the program so im not really sure how to write a code or formula to take a X number of values in a string and add them all together. maybe i entered it wrong, not sure.

ex:



X, X, X,......X
1, 2, 3, 4, 5, 6, 7, 8, 9
1.2, 1.8

<thead>
[TH="align: center"][/TH]
[TH="align: center"]H[/TH]

</thead><tbody>
[TD="align: center"]9[/TD]

[TD="align: right"]X+X+X+X+.....+X[/TD]

[TD="align: center"]10[/TD]

[TD="align: right"]45[/TD]

[TD="align: center"]11[/TD]

[TD="align: right"]3[/TD]

</tbody>
 
Upvote 0
Formula solution but it's fugly:




[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: #DAE7F5"]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: #DAE7F5"]I9[/TH]
[TD="align: left"]{=SUM(TRIM(MID(SUBSTITUTE(H9,", ",REPT(" ",LEN(H9))), (ROW(OFFSET($A$1,0,0,(LEN(H9)-LEN(SUBSTITUTE(H9,", ","")))/2+1))-1)*LEN(H9)+1, LEN(H9)))+0)}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]



WBD


i didnt enter with ctrl shift enter and i did that. works perfectly, thank you so much
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

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