Ask Experts Questions for FREE Help !
Ask
    nynenyne's Avatar
    nynenyne Posts: 3, Reputation: 1
    New Member
     
    #1

    Aug 3, 2009, 08:48 AM
    values of mix data codes in one cell
    I am trying to put together a spreadsheet in Excel 2007 for a specific style of time study. The code strings are varied in their length and go in one cell. An example would be M4P5 M3G1, or "M7P2 M3G3X4" and I need the cells with these codes to be recognized as the sum of the numbers contained within. Is this possible?

    Thanks,
    DC
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #2

    Aug 3, 2009, 01:10 PM
    Quote Originally Posted by nynenyne View Post
    I am trying to put together a spreadsheet in Excel 2007 for a specific style of time study. The code strings are varied in their length and go in one cell. An example would be M4P5 M3G1, or "M7P2 M3G3X4" and I need the cells with these codes to be recognized as the sum of the numbers contained within. Is this possible?

    Thanks,
    DC
    Can you expand you question to include a set of example cells and a set of example answers.
    nynenyne's Avatar
    nynenyne Posts: 3, Reputation: 1
    New Member
     
    #3

    Aug 3, 2009, 01:37 PM

    Yes, of course

    An example would be

    Cell C3 "M4G1 M4P5" Total (answer) 14 (4+1+4+5)
    Cell C4 "M3G1 M7P5X4" Total (answer) 20 (3+1+7+5+4)
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #4

    Aug 3, 2009, 03:54 PM

    I don't know of a function or formula to do this simply, so I wrote a little User Defined Function to do it for you.

    First, here's the code:
    Code:
    Option Explicit
    
    Function AddNumText(txt As Range)
    'JBeaucaire (8/3/2009)
    'Add all the numbers in a text string together
    Dim Val As String, holder As Long, i As Long
    
    Val = txt.Value
    holder = 0
    
        For i = 1 To Len(Val)
            If IsNumeric(Mid(Val, i, 1)) Then _
                holder = holder + Mid(Val, i, 1)
        Next i
    AddNumText = holder
    End Function
    How to install the User Defined Function:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save your sheet

    The function is installed and ready to use.

    If the text string were in A2, then in another cell enter this formula:
    =AddNumText(A2)

    Hope this helps.
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #5

    Aug 3, 2009, 03:59 PM
    Here's an alternate version that could be used with a RANGE of cells and still work.
    Code:
    Option Explicit
    
    Function AddNumText(txt As Range)
    'JBeaucaire (8/3/2009)
    'Add all the numbers in a text string together
    Dim Val As String, cell As Range, holder As Long, i As Long
    holder = 0
    
        For Each cell In txt
            Val = cell.Value
            For i = 1 To Len(Val)
                If IsNumeric(Mid(Val, i, 1)) Then _
                    holder = holder + Mid(Val, i, 1)
            Next i
        Next cell
        
    AddNumText = holder
    End Function
    With this one, you could use this and it would add up the digits in all the cells in the range:
    =AddNumText(A2:A10)


    The original code in the post above is good for one cell only.
    nynenyne's Avatar
    nynenyne Posts: 3, Reputation: 1
    New Member
     
    #6

    Aug 5, 2009, 12:53 PM

    Thank you very much, ill have fun playing with this!

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Lock cell that has data, unlock others [ 21 Answers ]

How to lock only cell that has data, and unlock others while they no data. I need solution with: Data-Validation-Settings-Custom-Formula. Thanks! Sorry for my "english"

Assigning cell values from one worksheet to another [ 1 Answers ]

In a workbook, I have an "inputs worksheet". It has data that I want to use across multiple other worksheets in the workbook. Example in worksheet "EX" A B C 1 12 13 14 2 56 57 58 In my target worksheet ABC, rather then assigning the an EX worhsheet cell value...

Subsidy unlock codes for motorola cell phones [ 1 Answers ]

If anyone knows how to unlock subsidy codes for motorola rzors can you please help me it would b greatly appreciated.

Loading different data into a cell [ 2 Answers ]

Hello everyone, I'm looking for a way to load different data into a cell, or part of the page on the click of a link. So I've got a load of links across the top of the page, and when each is clicked, different data is displayed (ideally more HTML) in the rest of the page, without the main...

Cell Phone Codes [ 1 Answers ]

What is a good web site that has free codes for a Nokia 6030 cell phone


View more questions Search