+ Reply to Thread
Results 1 to 6 of 6

trim string before the space - macro request.

  1. #1
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    trim string before the space - macro request.

    I am writing to seek help, in creating a simple macro which can trim string in column A, by starting from the right-side and trimming the anything before the first space and displaying the output (string before the space - starting from the right-side) in column B.

    I have attached an example file below, showing the input string in sheet1 and desired output is shown in sheet2 of the file.
    test_1.xls

    Please note:My actual dataset is more than 200,000 records.

    Many thanks for your time and help.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: trim string before the space - macro request.

    You need to do something like this

    Please Login or Register  to view this content.
    not in excel at mo, so not tested.

    You can do this as formula, using MID and FIND

    Please Login or Register  to view this content.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Valued Forum Contributor wenqq3's Avatar
    Join Date
    04-01-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    868

    Re: trim string before the space - macro request.

    Simple way that no need macro.
    1. Text to column
    2. Delimited
    3. Choose "SPACE"
    4. Column data format = TEXT for all
    5. You will get multi column.
    6. Delete the column you dont want.
    7. Combine again all column like =A1 & " " & B1 & " " & C1
    8. Drag down to 200000++ records.
    -If the problem is solved, please mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved".

    -Always upload a workbook before start your question
    To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.

    +++ If my answer(s) helped you, please add me reputation by click on * +++

  4. #4
    Valued Forum Contributor wenqq3's Avatar
    Join Date
    04-01-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    868

    Re: trim string before the space - macro request.

    =LEFT(A1,LEN(A1)-LEN(RIGHT(A1,LEN(A1)-FIND(" ",A1)))) <--Wrong

    Another way by function.

    Edit, this is correct

    =IF( ISERROR( FIND(" ",A1) ),A1,RIGHT(A1, LEN(A1)-FIND("~", SUBSTITUTE(A1," ","~", LEN(A1)-LEN(SUBSTITUTE(A1," ",""))
    Last edited by wenqq3; 09-09-2014 at 04:59 AM.

  5. #5
    Registered User
    Join Date
    01-20-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: trim string before the space - macro request.

    Hi missy, I have attached a working document. test_1.xls

    HTH

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: trim string before the space - macro request.

    The output is on sheet1 column B, but can be changed if you want it on separate sheet.
    Attached Files Attached Files

+ 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. Substitue Leaves Excessive Space, Cannot Use TRIM
    By goss in forum Excel General
    Replies: 4
    Last Post: 05-22-2012, 02:06 PM
  2. [SOLVED] Trim Specific Values and Remove last right space
    By jantonio in forum Excel General
    Replies: 3
    Last Post: 05-02-2012, 08:40 AM
  3. [SOLVED]Separate cell string at the first delimiter (ex. space) - macro
    By sky123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-30-2011, 05:46 PM
  4. Macro to separate string if space between
    By hunsnowboarder in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-30-2009, 12:53 PM
  5. Trying to trim a trailing space char and the Trim function isn't working
    By Psychochook in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2007, 11:28 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