+ Reply to Thread
Results 1 to 13 of 13

How to Trim a string

  1. #1
    Forum Contributor
    Join Date
    11-29-2012
    Location
    Coimbatore, India
    MS-Off Ver
    Excel 2010
    Posts
    101

    How to Trim a string

    Hi Everyone,

    I need a trim function that will do the following thing.

    For example consider i'm assigning this line "Value - $10 for pickup" to a variable. I need to get that $10 alone from that line and assign to another variable. this line varies from time to time. sometimes it will be like "After Pickup $5,000 for drop to home". So what I need is i need to extract the amount alone that is $10, $5,000 from any line and place it in a variable. How to handle this. Any Idea. Thanks in advance.

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: How to Trim a string

    for example
    Please Login or Register  to view this content.
    Last edited by nilem; 01-16-2013 at 11:01 AM. Reason: add comment

  3. #3
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: How to Trim a string

    If your Text is in A1 cell use this formula

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: How to Trim a string

    If your Text is in A1 cell use this formula

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-29-2012
    Location
    Coimbatore, India
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: How to Trim a string

    Quote Originally Posted by kvsrinivasamurthy View Post
    If your Text is in A1 cell use this formula

    Please Login or Register  to view this content.
    Hi. Thank you for the reply. I would like to let you know that i'm not taking the text from a cell in excel sheet. I'm taking the text from a word document and assigning it to a variable and then passing that variable to an excel cell. so inbetween i want a trim function to happen. I'm attaching the code for your reference. This should throw some light.

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    11-29-2012
    Location
    Coimbatore, India
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: How to Trim a string

    Quote Originally Posted by nilem View Post
    for example
    Please Login or Register  to view this content.
    Thank You for the reply. I posted my concern in the previous post.Please let me know if you need any additional inputs

  7. #7
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: How to Trim a string

    In your code Change this line


    Please Login or Register  to view this content.

    as

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    11-29-2012
    Location
    Coimbatore, India
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: How to Trim a string

    Quote Originally Posted by kvsrinivasamurthy View Post
    In your code Change this line


    Please Login or Register  to view this content.

    as

    Please Login or Register  to view this content.
    That's awesome piece of code. works like charm.
    I have one more thing to say you.
    sometimes there will be % instead of $. For example I will have a line like "30% commission, after drop". So in this case what i'm supposed to do. I need to seperate that 30% alone from the whole sentence. Thanks in advance

  9. #9
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: How to Trim a string

    Will the figure like 30% appear always in the begining.

  10. #10
    Forum Contributor
    Join Date
    11-29-2012
    Location
    Coimbatore, India
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: How to Trim a string

    Quote Originally Posted by kvsrinivasamurthy View Post
    Will the figure like 30% appear always in the begining.
    No. I just noted that in most of the cases it will be in the begining. But there are chances it might come in the middle as well.
    Last edited by sugaprasad; 01-17-2013 at 07:46 AM.

  11. #11
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: How to Trim a string

    After this line

    Please Login or Register  to view this content.
    Pl add this code


    Please Login or Register  to view this content.
    Before this line

    Please Login or Register  to view this content.
    This will extract words containing % or $.
    Last edited by kvsrinivasamurthy; 01-18-2013 at 04:22 AM.

  12. #12
    Forum Contributor
    Join Date
    11-29-2012
    Location
    Coimbatore, India
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: How to Trim a string

    Quote Originally Posted by kvsrinivasamurthy View Post
    After this line

    Please Login or Register  to view this content.
    Pl add this code


    Please Login or Register  to view this content.
    Before this line

    Please Login or Register  to view this content.
    This will extract words containing % or $.
    Wow..that's simply awesome. Its working great. Thank you so much for your help. I'm going to mark this thread as solved.

  13. #13
    Forum Contributor
    Join Date
    11-29-2012
    Location
    Coimbatore, India
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: How to Trim a string

    Quote Originally Posted by kvsrinivasamurthy View Post
    After this line

    Please Login or Register  to view this content.
    Pl add this code


    Please Login or Register  to view this content.
    Before this line

    Please Login or Register  to view this content.
    This will extract words containing % or $.
    This Code is working great. But i'm facing one problem here. Suppose if there is no space between $ value and the next word its not triming the $value alone.

    For example consider there is a line "After Pickup $5,000for drop to home"

    In the above sentence there is no space between $5000 and for. So $5000for is getting assigned to the TheContent variable instead of $5000.
    I would like to assign only the number value to TheContent variable. Can you please help me for one more time.

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