+ Reply to Thread
Results 1 to 7 of 7

Split Columns (delimter multiple space)

Hybrid View

  1. #1
    Registered User
    Join Date
    07-01-2020
    Location
    Yerevan
    MS-Off Ver
    2010
    Posts
    44

    Split Columns (delimter multiple space)

    Hi All,

    In Column A, I have a text data. Between words there is one space. I would like to split the column to multiple columns whenever there is more than one space between words (such that delimiter is 2 or more spcaes)

    I thought that splitting the text when meeting more than one blank space could be a good idea.

    Can Anyone assist with VBA Code please?

    Many thanks,

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Split Columns (delimter multiple space)

    Try
    Sub test()
        Dim r As Range
        With CreateObject("VBScript.RegExp")
            .Global = True
            .Pattern = "\s{2,}"
            For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
                r = .Replace(r, Chr(2))
            Next
        End With
        Columns("a").TextToColumns [a1], 1, other:=True, otherchar:=Chr(2)
    End Sub

  3. #3
    Registered User
    Join Date
    07-01-2020
    Location
    Yerevan
    MS-Off Ver
    2010
    Posts
    44

    Re: Split Columns (delimter multiple space)

    thank you this works perfectly

  4. #4
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: Split Columns (delimter multiple space)

    Quote Originally Posted by lilit2222 View Post
    thank you this works perfectly
    We do not know whose post you are referring to. You should make that clear for future readers of this thread.

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: Split Columns (delimter multiple space)

    Assuming your data is in Column A, give this macro a try...
    Sub SplitOnMultipleSpaces()
      Columns("A").Replace Space(2), "|", xlPart, , , , False, False
      Columns("A").Replace "| ", "|"
      Columns("A").TextToColumns , xlDelimited, , True, False, False, False, False, True, "|"
    End Sub

  6. #6
    Registered User
    Join Date
    07-01-2020
    Location
    Yerevan
    MS-Off Ver
    2010
    Posts
    44

    Re: Split Columns (delimter multiple space)

    Hi and thanks,

    Does this also take into account if there are two or more spaces?

  7. #7
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: Split Columns (delimter multiple space)

    Quote Originally Posted by lilit2222 View Post
    Does this also take into account if there are two or more spaces?
    Not sure if you are asking me or jindon that question. Mine does and, while I haven't done anything with Regular Expressions in over 30 years, jindon's looks like it should. In any event, why not just try each of our routines and see. Either do that on a copy of your workbook or, if you do it on your live workbook, simply close it without saving if the code does not work.

+ 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] Split single column to multiple columns (using space as delimiter) - VBA code
    By niyidrums in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-15-2020, 03:58 PM
  2. [SOLVED] split numbers with space to multiple column
    By finalazy in forum Excel General
    Replies: 10
    Last Post: 08-26-2016, 10:13 AM
  3. [SOLVED] Split A List my Space in adjacent Columns
    By mtilbury in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-28-2015, 10:15 AM
  4. Replies: 4
    Last Post: 07-25-2013, 05:28 AM
  5. Macro to split Cells delimter comma to multiple Rows.
    By pavan5183 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-17-2013, 10:24 AM
  6. Text to columns, split at first space only
    By Wowbagger in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 06-21-2012, 01:27 PM
  7. Replies: 1
    Last Post: 08-30-2005, 12:05 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