+ Reply to Thread
Results 1 to 9 of 9

Trim cell character to make computation

  1. #1
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Trim cell character to make computation

    Hi, I've a problem to set formulas, say in column B using substitute function to replace column A text

    Column A

    A1: +2M+4M
    A2: +1M+3.5M
    A3: +0.5M+3.6M

    Column B

    B1: +Value(Substitute(A1,"M",""))
    B2: +Value(Substitute(A2,"M",""))
    B3: +Value(Substitute(A3,"M",""))

    The result in column B shows error #Value!

    Grateful if anyone could help.

    Many thanks.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,858

    Re: Trim cell character to make computation

    First, use "=" instead of "+" to begin a formula.

    Second, when you execute SUBSTITUTE you get these results:

    +2+4
    +1+3.5
    +0.5+3.6

    None of those are numbers, they are arithmetic expressions. VALUE won't evaluate an expression for you. It just turns the string "123" into the number 123.

    You need to use VBA for what you want.

    Please Login or Register  to view this content.
    B1: =Eval(SUBSTITUTE(A1,"M",""))

    and so forth.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert wk9128's Avatar
    Join Date
    08-15-2020
    Location
    Australia
    MS-Off Ver
    365 V2403 and WPS V2022
    Posts
    3,558

    Re: Trim cell character to make computation

    First define a name, the name is CAL, and the placement formula is =EVALUATE(SUBSTITUTE($A1,"M",))

    Cell B1 formula =CAL , Drag down

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,858

    Re: Trim cell character to make computation

    Interesting that EVALUATE can be used in a defined name but not in a worksheet cell.

  5. #5
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Trim cell character to make computation

    For 6stringjazzer : I cannot make the codes work, with same error #value! *I've uploaded the Excel for your checking
    For wk9128 : I don't know where to define a name

    Hope you could further advise.
    Thx
    Attached Files Attached Files

  6. #6
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,213

    Re: Trim cell character to make computation

    Please try

    =SUMPRODUCT(--MID(SUBSTITUTE(SUBSTITUTE(A1,"M",),"+",REPT(" ",20)),{20,40},20))

    or
    =SUMPRODUCT(--TEXT(MID(SUBSTITUTE(SUBSTITUTE(A1,"M",),"+",REPT(" ",20)),ROW(A$1:A$9)*20,20),"0.0;-0.0;0;\0"))
    Attached Files Attached Files

  7. #7
    Forum Expert wk9128's Avatar
    Join Date
    08-15-2020
    Location
    Australia
    MS-Off Ver
    365 V2403 and WPS V2022
    Posts
    3,558

    Re: Trim cell character to make computation

    The attachments and formulas have been uploaded, and they are all in the attachments
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    03-27-2015
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Trim cell character to make computation

    Dear ALL,

    Thank you so much for the response.

    I've tested all options, and find using the codes is the best as column A may involve more than 2 items and sometimes minus signs as well.

    Thanks again

    Edward

  9. #9
    Forum Expert wk9128's Avatar
    Join Date
    08-15-2020
    Location
    Australia
    MS-Off Ver
    365 V2403 and WPS V2022
    Posts
    3,558

    Re: Trim cell character to make computation

    @chasoe You're Welcome. Glad to help . Thank You for the feedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] trim to match two sets of input-trim spaces around a character
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-21-2017, 12:33 PM
  2. [SOLVED] TRIM leading character
    By lemonap618 in forum Excel General
    Replies: 3
    Last Post: 01-20-2016, 11:01 PM
  3. [SOLVED] How can I Trim from the right to certain character
    By dschmitt in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 06-10-2015, 05:00 AM
  4. Replies: 2
    Last Post: 12-02-2013, 03:29 PM
  5. Trim surname down to 1 character
    By richardburrow in forum Excel General
    Replies: 2
    Last Post: 10-10-2011, 08:51 AM
  6. Removing character using Trim..
    By Jocote46 in forum Excel General
    Replies: 5
    Last Post: 05-13-2009, 01:57 PM
  7. [SOLVED] How to trim a character from a cell ?
    By dex in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-04-2005, 06:10 PM

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.6.0 RC 1