+ Reply to Thread
Results 1 to 2 of 2

Split string by line break into array

  1. #1
    Registered User
    Join Date
    02-12-2009
    Location
    columbus, ohio
    MS-Off Ver
    Excel 2003
    Posts
    1

    Smile Split string by line break into array

    hey,
    does anyone know how to read a multiline string in excel cells and put each line into a string array?

    for example

    in excell cells(1,1) = " option color
    option size
    option coating"


    i tried to use the following code but it doesn't work.

    --------------------------------------------------
    dim txt as String
    dim stringarray() as String
    txt=Cells(1,1)
    stringarray = Split(txt, vbCrLf)

    Cells(1,2)=stringarray(0)
    -------------------------------------------------

    my desired result would be:

    Cells(1,2) display "option color "

    the actualy result i got from my code is:

    Cells(1,2) display " option color
    option size
    option coating"


    so the problem is the Cells(1,2) doesn't show just one line, instead, it just show everything from Cells(1,1). how do i identify line break here?

    your help will be greatly appreciated!
    thank you

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: HELP! does anyone knows how to splite a string by line break into an array in VBA

    Welcome to the forum.

    Please take a few minutes to read the Forum Rules, and then edit your post to wrap your code with Code Tags.

    Split on vbLf instead of vbCrLf.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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