+ Reply to Thread
Results 1 to 8 of 8

Insering newline at every space

Hybrid View

mandukes Insering newline at every... 12-05-2013, 07:32 AM
Rem0ram Re: Insering newline at every... 12-05-2013, 07:42 AM
mandukes Re: Insering newline at every... 12-05-2013, 07:53 AM
JOHN H. DAVIS Re: Insering newline at every... 12-05-2013, 08:05 AM
mandukes Re: Insering newline at every... 12-05-2013, 08:12 AM
zbor Re: Insering newline at every... 12-05-2013, 07:47 AM
  1. #1
    Registered User
    Join Date
    10-23-2012
    Location
    LON
    MS-Off Ver
    Excel 2003
    Posts
    29

    Unhappy Insering newline at every space

    I have a text file with data arranged in the following order:

    Name Address Name Address Name Address ... so on

    I want to arrange it like:

    Name
    Address
    Name
    Address
    Name
    Address
    .
    .
    .
    so on

    How can I achieve this using VBA??
    I figured out that at every space, if I insert a new line than it will be solved.. but no idea how to do that??

    So my program is required to check a text file and insert a newline at every space it finds


    Regards

  2. #2
    Forum Contributor
    Join Date
    06-18-2012
    Location
    Chennai, India
    MS-Off Ver
    Excel 2003, 2010
    Posts
    212

    Re: Insering newline at every space

    post a sample file...

  3. #3
    Registered User
    Join Date
    10-23-2012
    Location
    LON
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Insering newline at every space

    Quote Originally Posted by Rem0ram View Post
    post a sample file...
    sample file is attached

    Data.txt

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Insering newline at every space

    Does this help?

    Sub mandukes()
    Range(Cells(2, 1), Cells(2, ActiveSheet.UsedRange.Columns.count)).Copy
    Cells(3, 1).PasteSpecial Transpose:=True
    Range(Cells(2, 1), Cells(2, ActiveSheet.UsedRange.Columns.count)).Delete
    End Sub
    assumes original data is on row 2.

  5. #5
    Registered User
    Join Date
    10-23-2012
    Location
    LON
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Insering newline at every space

    Quote Originally Posted by JOHN H. DAVIS View Post
    Does this help?

    Sub mandukes()
    Range(Cells(2, 1), Cells(2, ActiveSheet.UsedRange.Columns.count)).Copy
    Cells(3, 1).PasteSpecial Transpose:=True
    Range(Cells(2, 1), Cells(2, ActiveSheet.UsedRange.Columns.count)).Delete
    End Sub
    assumes original data is on row 2.

    Not working
    Last edited by mandukes; 12-05-2013 at 08:15 AM.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Insering newline at every space

    Maybe:

    Sub mandukes()
        Range("A2").Select
        Selection.TextToColumns Destination:=Range("A2"), DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
            Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
            :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)), _
            TrailingMinusNumbers:=True
    Range(Cells(2, 1), Cells(2, ActiveSheet.UsedRange.Columns.count)).Copy
    Cells(3, 1).PasteSpecial Transpose:=True
    Range(Cells(2, 1), Cells(2, ActiveSheet.UsedRange.Columns.count)).Delete
    End Sub
    Assumes original data is on row 2 of a spreadsheet.

  7. #7
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,028

    Re: Insering newline at every space

    You can Split them like this:

    Sub Example()
    'create an array to hold all of the words
    Dim Words() As String
    'split string into words, using space as delimiter
    Words = Split(txt, " ")
    MsgBox "String contains " & (UBound(Words) + 1) & " words"
    
    ' so you can now write them in new form as Words(0), Words(1), Words(2) etc
    End Sub
    Never use Merged Cells in Excel

+ 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. How to replace space with newline
    By utpalmtbi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-11-2013, 09:13 PM
  2. [SOLVED] Problem in insering header picture in word through excel
    By spmltr in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-22-2012, 05:48 AM
  3. Insering empty rows after each
    By HarryKlein in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-31-2011, 06:20 AM
  4. insering empty row based on a condition
    By darkhorse4321 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2010, 02:16 AM
  5. Insering an image on a specific cell
    By Moiz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-10-2005, 07:10 AM

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