#1
|
|||
|
|||
Sum values within a single cell
Hi,
Is it possible to sum values within one cell of Excel. I appreciate its probably not good practice BUT its an export from a 3rd party application and rather having to juggle the data a sum from that single cell would be ideal? Example: A1 - 0.1, 1.5, '0.5, '1.2 B2 - Sum of A1 (excluding the ' and ,) Cheers |
#2
|
||||
|
||||
Just to clarify, it sounds like you're saying that A1 contains not a number but a character string "0.1, 1.5, '0.5, '1.2". Is that right?
If so, you can get Excel to split the character string up into individual numbers and then add the numbers together. But the SUM function, if you use it at all, won't come in until the very end. First you have to explain to Excel how to break up the string into pieces. Do you want to continue? |
#3
|
||||
|
||||
You could use a UDF for this:
Code:
Public Function SUMCELLNUMS(Source As Range, StrSplit As String) Dim StrIn As String, StrTmp As String, ValOut, i As Long StrIn = Trim(Replace(Source.Text, "'", "")) For i = 0 To UBound(Split(StrIn, StrSplit)) StrTmp = Trim(Split(StrIn, StrSplit)(i)) If IsNumeric(StrTmp) Then ValOut = Evaluate(ValOut + StrTmp) End If Next SUMCELLNUMS = ValOut End Function =SUMCELLNUMS(A1, ",") where A1 is the cell reference and "," is the delimiter.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
Quote:
|
#5
|
|||
|
|||
Quote:
Thanks |
#6
|
||||
|
||||
Huh? What solution did Bob post?
The solution I posted works with xls and xlsm files, just not xlsx files...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Quote:
Again apologies for the confusion I really should read what I write |
#8
|
||||
|
||||
Right, it was macropod's solution. But Paul, I don't see why you told him it would work with .xlsx files. Your solution is a user-written function, which by definition (right?) means it has to be stored in an .xlsm. Now, I'm all for that; these days I sometimes store a new workbook as .xlsm even though I haven't yet written or imagined any code for it, just because experience leads me to believe I will sooner or later. But how would your macro work with an .xlsx?
And shabbaranks, if you really can't use .xlsm, why not store it as an .xls? That'll allow embedded VBA. |
#9
|
|||
|
|||
Bingo bango bongo - works a treat thanks. Just for my own sake - why xls and not xlsx? Thanks again
|
#10
|
||||
|
||||
In the old versions of Excel, up to 2003, workbooks were named .xls and macros were stored directly in the workbooks. But with increasing concern about malicious software, Microsoft introduced a distinction between workbooks that can contain VBA code and those that can't. The plain-vanilla workbook is now .xlsx. If you want to write a macro for one of your workbooks, it won't be saved in an .xlsx; you have to store it with extension .xlsm. This provides a little extra warning about the content to a user opening a workbook, in addition to the warnings that pop up.
I graduated straight from 2003 to 2010, so I don't know whether this distinction started with 2007 or 2010. Does that help? If I skipped over an important part of the explanation, feel free to keep asking. |
#11
|
||||
|
||||
Quote:
Quote:
Now, compare what I wrote against your posts...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
||||
|
||||
Oops. I read it, I just read it too fast and wrong; I thought you wrote "...works with xls and xlsm files, not just xlsx files". My bad.
|
#13
|
||||
|
||||
Quote:
I also read it wrong....
__________________
Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post |
#14
|
||||
|
||||
That is what I wrote...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
||||
|
||||
Not unless you changed it later. I thought you wrote "...not just .xlsx files"; what appears there now is "...just not .xlsx files". I'm glad I'm not the only one whose eyes found it easy to reverse the two words.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Summing up values in a Single Merge Field | Beowolf | Mail Merge | 1 | 03-07-2014 03:26 PM |
Finding Earned Values for Different Baselines in a single project | pratik6312 | Project | 1 | 08-22-2013 11:18 AM |
How to count multiple values in a single cell, except zero? | iuliandonici | Excel | 1 | 04-13-2011 09:45 PM |
Sum & difference between multiple values in a single cell | iuliandonici | Excel | 4 | 04-13-2011 09:27 PM |
How can I write the following (whole) formula in a single cell? | Learner7 | Excel | 1 | 07-19-2010 10:06 AM |