Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-09-2014, 05:26 AM
shabbaranks shabbaranks is offline Sum values within a single cell Windows 7 64bit Sum values within a single cell Office 2007
Advanced Beginner
Sum values within a single cell
 
Join Date: Mar 2011
Posts: 89
shabbaranks is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 05-09-2014, 02:40 PM
BobBridges's Avatar
BobBridges BobBridges is offline Sum values within a single cell Windows 7 64bit Sum values within a single cell Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

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?
Reply With Quote
  #3  
Old 05-09-2014, 06:20 PM
macropod's Avatar
macropod macropod is offline Sum values within a single cell Windows 7 32bit Sum values within a single cell Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
Simply add the above function to a normal code module in the workbook, then use a formula like:
=SUMCELLNUMS(A1, ",")
where A1 is the cell reference and "," is the delimiter.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 05-11-2014, 11:53 PM
shabbaranks shabbaranks is offline Sum values within a single cell Windows 7 64bit Sum values within a single cell Office 2007
Advanced Beginner
Sum values within a single cell
 
Join Date: Mar 2011
Posts: 89
shabbaranks is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
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
Simply add the above function to a normal code module in the workbook, then use a formula like:
=SUMCELLNUMS(A1, ",")
where A1 is the cell reference and "," is the delimiter.
Perfecto!! Thanks
Reply With Quote
  #5  
Old 05-12-2014, 04:45 AM
shabbaranks shabbaranks is offline Sum values within a single cell Windows 7 64bit Sum values within a single cell Office 2007
Advanced Beginner
Sum values within a single cell
 
Join Date: Mar 2011
Posts: 89
shabbaranks is on a distinguished road
Default

Quote:
Originally Posted by BobBridges View Post
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?
Could you elaborate on this for me please? The reason I ask is although the solution provided by BobBridges works the application I am trying to use it with doesn't support xlsxm files only xls or xlsx so I was wondering if your solution supports this?

Thanks
Reply With Quote
  #6  
Old 05-12-2014, 05:02 AM
macropod's Avatar
macropod macropod is offline Sum values within a single cell Windows 7 32bit Sum values within a single cell Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by shabbaranks View Post
the solution provided by BobBridges works
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]
Reply With Quote
  #7  
Old 05-12-2014, 05:52 AM
shabbaranks shabbaranks is offline Sum values within a single cell Windows 7 64bit Sum values within a single cell Office 2007
Advanced Beginner
Sum values within a single cell
 
Join Date: Mar 2011
Posts: 89
shabbaranks is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Huh? What solution did Bob post?

The solution I posted works with xls and xlsm files, just not xlsx files...
Sorry not bob it was you. If you create an xlsx and you apply the VB as soon as you exit and go back into it you haven't got the code anymore (because its now a xlsx) and so the calculations don't work - unless Im missing something?

Again apologies for the confusion I really should read what I write
Reply With Quote
  #8  
Old 05-12-2014, 07:12 AM
BobBridges's Avatar
BobBridges BobBridges is offline Sum values within a single cell Windows 7 64bit Sum values within a single cell Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

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.
Reply With Quote
  #9  
Old 05-12-2014, 07:20 AM
shabbaranks shabbaranks is offline Sum values within a single cell Windows 7 64bit Sum values within a single cell Office 2007
Advanced Beginner
Sum values within a single cell
 
Join Date: Mar 2011
Posts: 89
shabbaranks is on a distinguished road
Default

Bingo bango bongo - works a treat thanks. Just for my own sake - why xls and not xlsx? Thanks again
Reply With Quote
  #10  
Old 05-12-2014, 08:02 AM
BobBridges's Avatar
BobBridges BobBridges is offline Sum values within a single cell Windows 7 64bit Sum values within a single cell Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

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.
Reply With Quote
  #11  
Old 05-13-2014, 12:57 AM
macropod's Avatar
macropod macropod is offline Sum values within a single cell Windows 7 32bit Sum values within a single cell Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by shabbaranks View Post
If you create an xlsx and you apply the VB as soon as you exit and go back into it you haven't got the code anymore (because its now a xlsx) and so the calculations don't work - unless Im missing something?
Quote:
Originally Posted by BobBridges View Post
But Paul, I don't see why you told him it would work with .xlsx files.
If you two would take the time to read my replies, you just might save yourselves some confusion and me some time!
Quote:
Originally Posted by macropod View Post
The solution I posted works with xls and xlsm files, just not xlsx files...
Now, compare what I wrote against your posts...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 05-13-2014, 07:50 AM
BobBridges's Avatar
BobBridges BobBridges is offline Sum values within a single cell Windows 7 64bit Sum values within a single cell Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

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.
Reply With Quote
  #13  
Old 05-13-2014, 09:45 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline Sum values within a single cell Windows 7 64bit Sum values within a single cell Office 2010 64bit
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,771
Pecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant future
Default

Quote:
Originally Posted by BobBridges View Post
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.

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
Reply With Quote
  #14  
Old 05-13-2014, 03:08 PM
macropod's Avatar
macropod macropod is offline Sum values within a single cell Windows 7 32bit Sum values within a single cell Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by BobBridges View Post
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.
That is what I wrote...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #15  
Old 05-13-2014, 03:41 PM
BobBridges's Avatar
BobBridges BobBridges is offline Sum values within a single cell Windows 7 64bit Sum values within a single cell Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

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.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sum values within a single cell 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
Sum values within a single cell How to count multiple values in a single cell, except zero? iuliandonici Excel 1 04-13-2011 09:45 PM
Sum values within a single cell Sum & difference between multiple values in a single cell iuliandonici Excel 4 04-13-2011 09:27 PM
Sum values within a single cell How can I write the following (whole) formula in a single cell? Learner7 Excel 1 07-19-2010 10:06 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:38 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft