Lets say there is some text in a cell that reads
"this is a block of text (.7) and in this block of text (1.2) there are numbers (2.5) and these numbers need to be added together (.4)"
The answer to the sum of all these numbers would be .7+1.2+2.5+.4= 4.8
My question is, is there a way that I can have excel add all the numbers together from a block of text and just output the answer? It will always be the sum of the numbers and the numbers will always be positive. The amount of numbers will vary, it could be 2 it could be 15, could be anything.
What I have tried so far: I've tried "=sum" and highlighting the entire cell which always gives the answer "0"
Try the following User Defined Function:
User Defined Functions (UDFs) are very easy to install and use:
If you save the workbook, the UDF will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx
To remove the UDF:
To use the UDF from Excel:
=myfunction(A1)
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
and for specifics on UDFs, see:
http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
Macros must be enabled for this to work!
EDIT#1:
The original code tries to convert a standalone period into a number. Replace the original UDF with this version:
EDIT#2:
This version (VERSION 3) will only process numbers encapsulated in parens:
Here is a UDF using Regular Expressions which will add only those values that are within parentheses:
Explanation of the Regex pattern
capture floating point numbers within parentheses, integer portion optional
Options: Case insensitive; ^$ match at line breaks
\(
(\d*(?:\.\d+)?)
\d*
*
(?:\.\d+)?
?
\.
\d+
+
\)
Created with RegexBuddy
This array formula will do it:
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.