+ Reply to Thread
Results 1 to 4 of 4

Extracting from a string

  1. #1
    Registered User
    Join Date
    12-08-2013
    Location
    Abertillery
    MS-Off Ver
    Excel 2007,2010
    Posts
    17

    Extracting from a string

    Hi Everyone

    What i would like to achieve is to be able to do the following, original data is in column A1 data required is shown here in A2, i can get the data shown in A3 using
    =LEFT(A2,FIND(" ",A2)+1) etc down the column. But ideally i want to be able to run a macro that would convert the data in column A1 to that in A2 but keep it in column A1 only and then loop down each row to convert each entry in column A1, is this possible do any of you kind folk have any suggestions

    A1______________A2__________A3
    Name
    Warburton David__D Warburton__Warburton D
    Jones Paul_______P Jones______Jones P
    Hughes Mark_____M Hughes____Hughes M

    Merry Christmas
    David

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Extracting from a string

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-08-2013
    Location
    Abertillery
    MS-Off Ver
    Excel 2007,2010
    Posts
    17

    Re: Extracting from a string

    Hi yudlugar

    I think i understand the first line counts the number of rows of data the second line splits and concatenates, what does the (0) do on the end?

    Many thanks
    David

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Extracting from a string

    Please Login or Register  to view this content.
    That takes the last cell in column A (A65536 for me in 2003), then .end(xlup) is similar to pressing ctrl+up to move back to the last cell with data in and .row returns the row number.

    Therefore:
    Please Login or Register  to view this content.
    Is the reference for column A from row 2 to the last row with data in and
    Please Login or Register  to view this content.
    steps through each cell in that range one at a time, assigning the variable cl to the cell

    Please Login or Register  to view this content.
    will split the string cl (the value of the cell) into an array of elements, delimited by spaces. The array will start at the index 0 and move up to the total number of elements. So for a string like "LastName Firstname" it would return:
    "LastName" as element 0
    and
    "FirstName as element 1
    Please Login or Register  to view this content.
    refers to the first element of the created array (LastName) and
    Please Login or Register  to view this content.
    refers to the second element of the created array (FirstName)

    Finally:
    Please Login or Register  to view this content.
    The Left function takes the string in the first arguement and truncates it to the first n letters, where n is the second arguement. In our example it will therefore give the first letter of FirstName (F).
    putting it all together you get:
    Please Login or Register  to view this content.
    which gives
    F & " " & LastName
    which is
    F LastName
    and this is assigned to cl.value, which overwrites the current value, and then moves onto the next cell.

+ 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. Replies: 12
    Last Post: 03-20-2013, 05:46 PM
  2. Extracting alphanumeric value from the string.
    By AlKey in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-21-2009, 01:51 PM
  3. Extracting characters from a string
    By incognito in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-30-2007, 03:18 AM
  4. Extracting 28 from a string
    By ephie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-02-2006, 12:17 PM
  5. Extracting a string
    By Peter Rooney in forum Excel General
    Replies: 5
    Last Post: 06-20-2006, 01:40 PM

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