+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Cell Calculation with Text

  1. #1
    Registered User
    Join Date
    01-24-2011
    Location
    In a House on earth
    MS-Off Ver
    Excel 2007
    Posts
    18

    Question Cell Calculation with Text

    How can I get excel to calculate with a cell if its contents is a number and letters?

    Eg.

    A1= 2
    A2= 230gr

    I want to calculate cell A2 multiplied by A1 (A1*A2) the answer is supposed to be "460"
    * * * * * * *
    How beautiful it is to excel, and the goodness of giving from your heart. || Always strive to excel, but only on weekends. - Richard Rorty & Robert Mondavi

  2. #2
    Forum Guru Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007
    Posts
    3,521

    Re: Cell Calculation with Text

    If we assume the right two characters of A2 are always text then:

    =A1*LEFT(A2,LEN(A2)-2)

    Will the string always be NNNxx, where N= numeric and x = alpha?
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,788

    Re: Cell Calculation with Text

    depends what's actually in a2 but
    =A1*LOOKUP(9.99E+307,--MID(A2,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A2&1234567890)),ROW(INDIRECT("1:"&LEN(A2)))))
    is one way
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Registered User
    Join Date
    01-24-2011
    Location
    In a House on earth
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Cell Calculation with Text

    Well my strings might all be different.

    I might have string vary from 2-to-4 Numeric values and 1-to-2 alpha
    * * * * * * *
    How beautiful it is to excel, and the goodness of giving from your heart. || Always strive to excel, but only on weekends. - Richard Rorty & Robert Mondavi

  5. #5
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,772

    Re: Cell Calculation with Text

    It would be best to get rid of the text, and put the units, if necessary, in another column.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Valued Forum Contributor
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    380

    Re: Cell Calculation with Text

    You could use a User Defined Function to remove the text characters...
    Public Function RmvText(inString As String)
        Dim x           As Integer    'LOOPING COUNTER
        Dim vText       As Variant    'CHARACTER HOLDER
    
        For x = 1 To Len(inString)
            vText = Mid(inString, x, 1)
            If IsNumeric(vText) Or vText = "." Then RmvText = RmvText & vText
        Next x
    
    End Function
    Last edited by dangelor; 12-25-2011 at 09:21 PM. Reason: Added test for decimal

  7. #7
    Registered User
    Join Date
    01-24-2011
    Location
    In a House on earth
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Cell Calculation with Text

    Quote Originally Posted by dangelor View Post
    You could use a User Defined Function to remove the text characters...
    Public Function RmvText(inString As String)
        Dim x As Integer
        Dim vText As Variant
        For x = 1 To Len(inString)
            vText = Mid(inString, x, 1)
            If IsNumeric(vText) Then RmvText = RmvText & vText
        Next x
    End Function
    I will never figure out how and where to use this, but thanks.
    .
    .

    Quote Originally Posted by shg View Post
    It would be best to get rid of the text, and put the units, if necessary, in another column.
    Been thinking the same thing. but then its alot of work , and the sheet might get confusing to idiots who dont understand it (when I'm ready to share it)
    Last edited by anonymust; 12-25-2011 at 06:21 PM. Reason: Two answers in one.
    * * * * * * *
    How beautiful it is to excel, and the goodness of giving from your heart. || Always strive to excel, but only on weekends. - Richard Rorty & Robert Mondavi

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    1,974

    Re: Cell Calculation with Text

    @martindwilson, your formula is returning "TRUE" instead of a number. I am trying to understand the concept but I can't fully understand the principles used here.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  9. #9
    Forum Guru Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007
    Posts
    3,521

    Re: Cell Calculation with Text

    Martin's formula returns a valid number (460, using your examples in post #1) for me.
    Perhaps you should upload a sample workbook.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  10. #10
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    1,974

    Re: Cell Calculation with Text

    Palmetto, you are right. I opened a new workbook and tested it again and it worked this time.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  11. #11
    Registered User
    Join Date
    08-21-2011
    Location
    SL
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Cell Calculation with Text

    If your numbers are always on starting,

    =A1*LOOKUP(9.9999E+307,--LEFT(0&A2,ROW($A$1:$A$20)))

  12. #12
    Valued Forum Contributor
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    380

    Re: Cell Calculation with Text

    I will never figure out how and where to use this, but thanks
    See attached file.
    Attached Files Attached Files
    Last edited by dangelor; 12-25-2011 at 09:50 PM. Reason: Edited UDF to check for decimal

  13. #13
    Forum Guru Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    5,590

    Re: Cell Calculation with Text

    Would it not be easier to format A2 & A3
    Format Cells > Number > Custom
    Type:=
    #,##0"gr"
    Then in A3
    =A1*A2
    Just a thought.
    If you need any more information, please feel free to ask.

    However, if this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody! ....
    Also
    If you are satisfied by any members response to your problem please consider using the small Star icon botom left of thier post to show your appreciation.

  14. #14
    Registered User
    Join Date
    01-24-2011
    Location
    In a House on earth
    MS-Off Ver
    Excel 2007
    Posts
    18

    Question Re: Cell Calculation with Text

    What I am basically trying to do it calculate the cost of food items per gram or per milliliter and then see which on is the cheapest by the Kilo/Kilogram or Liter

    I've altered a function to something like this:
    =(-A1/LOOKUP(0,-LEFT(A2,{1,2,3,4})))*1000
    Where A1 is the cost of the item and A2 is the quantity of the item (in grams, milliliters, liters and kilo/kilogram,)
    Which is in layman's =(cost of food divided by how much ml/g received) * 1000

    Spaces
    If I have "121gr" in a cell it works perfectly.. but when I have "121 gr" in a cell it doesnt *notice the spacing between the alpha and numeric value*

    Different unit conversion? (convert KG and L into milliliters and grams)
    Sometimes I enter my data with: "kg" "L" and "K", examples:
    • 1kg
    • 1.2 L
    • 2.5k
    • 2.5 KG
    • 1.4L

    *notice the spacing between the alpha and numeric value*
    * * * * * * *
    How beautiful it is to excel, and the goodness of giving from your heart. || Always strive to excel, but only on weekends. - Richard Rorty & Robert Mondavi

  15. #15
    Forum Guru Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    5,590

    Re: Cell Calculation with Text

    You would be much better doing as shg suggested, put the units in a seperate cell.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However, if this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody! ....
    Also
    If you are satisfied by any members response to your problem please consider using the small Star icon botom left of thier post to show your appreciation.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0