+ Reply to Thread
Results 1 to 4 of 4

Convert string to column

Hybrid View

  1. #1
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Convert string to column

    Hi all...
    I have some code that works fine for smaller strings, but for the big ones, it's running much longer than I'd like. I'm sure there's a better way to accomplish the same thing.

    I have a text string that I'd like to convert into a list of words, not sorted or anything, just put into a column, where 1 word goes in each cell. The code below splits the string on single spaces and writes into the column.
    'find word count
    MyWordCount = Len(MyString) - Len(Replace(MyString, " ", "")) + 1
    
    Range("A1").Select
    
    'generate word lists
    For x = 0 To MyWordCount
        ActiveCell.Offset(x, 0) = Split(MyString, " ")(x)
    Next x
    The strings I tested with when I got this project were 500 -1000 words, and it worked fine. But it looks like the production data will be closer to 10,000, and that slowness gets pretty painful when it has to execute 3-5 times per run.

    Thanks for any help!
    Last edited by JP Romano; 08-09-2018 at 09:35 AM.

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Convert string to column

    May be
    Sub Test()
        MyWordCount = Len(MyString) - Len(Replace(MyString, " ", "")) + 1
    
        x = Split(MyString, " ")
        Range("A1").Resize(UBound(x) + 1).Value = Application.Transpose(x)
    End Sub
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Convert string to column

    Brilliant - thank you so much YasserKhalil!!!!!!!!!!!

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Convert string to column

    You're welcome. Glad I can offer some help
    Regards

+ 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: 5
    Last Post: 06-29-2016, 01:27 PM
  2. Replies: 4
    Last Post: 11-29-2015, 07:20 AM
  3. Replies: 1
    Last Post: 01-30-2013, 08:30 AM
  4. Convert String to Date in Column
    By brent_milne in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-12-2012, 06:14 PM
  5. [SOLVED] How to convert numeric data in an excel column into a string of comma values.
    By desgordon in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-04-2012, 12:10 PM
  6. Replies: 11
    Last Post: 02-22-2011, 07:07 PM
  7. convert excel column data to comma seperated string
    By faraz in forum Excel General
    Replies: 4
    Last Post: 04-28-2010, 03:40 AM

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