Consulting

Results 1 to 3 of 3

Thread: How to separate words in a cell

  1. #1
    VBAX Regular
    Joined
    Jul 2007
    Posts
    26
    Location

    How to separate words in a cell

    If I have a list of words in a cell and want to separate them in to other cells, how would I do that? These words are separated by commas within a certain cell and I want them to be in different cells.

    For example:
    Cell A1 contains: Mike, John, Pete, Sarah

    And I would like a macro to split this list so that:
    B1 contains: Mike
    C1 contains: John
    D1 contains: Pete
    E1 contains: Sarah


    Can anyone help?

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Try using:
    Data - Text to Columns
    Pick Delimited by and choose Comma

  3. #3
    VBAX Mentor Brandtrock's Avatar
    Joined
    Jun 2004
    Location
    Titonka, IA
    Posts
    399
    Location
    Quote Originally Posted by JKwan
    Try using:
    Data - Text to Columns
    Pick Delimited by and choose Comma
    That will parse your text, but it will begin in A1 and go to D1.

    This Sub routine will parse A1 into B1 to E1 and clear A1.
    [VBA]
    Sub Separate()
    With Range("A1")
    .TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
    Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
    :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1)), TrailingMinusNumbers:= _
    True
    .Clear
    End With
    End Sub
    [/VBA]

    Regards,
    Brandtrock




Posting Permissions

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