+ Reply to Thread
Results 1 to 12 of 12

Thread: Parsing Data Strings into Columns

  1. #1
    Valued Forum Contributor GuruWannaB's Avatar
    Join Date
    01-24-2008
    Location
    55 miles S.E. of the Buckeye Capital!! Go BUCKS!!
    MS-Off Ver
    2003
    Posts
    382

    Parsing Data Strings into Columns

    I have a spreadsheet that gathers information from multiple cells and strings the data into a long string - each piece of data broken by a comma in the string.

    In another spreadsheet, I copy this data string into column A on sheet 1 - starting on row 2 and down.

    On sheet 2 - and this is where I need help - I would like to have a macro that will take each data string on Sheet 1 column A and parse it out into multiple columns but the same row on Sheet 2.

    ColumnA Row2 Sheet1 -> changing to many columns on Sheet2 but still on the same row.

    The data string always represents the same number of data components - its just a matter of breaking it out and placing each data piece into its own column.

    Thanks in advance.
    Last edited by GuruWannaB; 05-04-2009 at 04:50 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Parsing Data Strings into Columns

    Hello GuruWannaB,

    If you have a workbook you can post, it will make answering your questions faster and easier.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor GuruWannaB's Avatar
    Join Date
    01-24-2008
    Location
    55 miles S.E. of the Buckeye Capital!! Go BUCKS!!
    MS-Off Ver
    2003
    Posts
    382

    Re: Parsing Data Strings into Columns

    Here's a generic example of the data strings.....

    Hope that helps - thanks again
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Parsing Data Strings into Columns

    Hello GuruWannaB,

    I take it the data will start in row 1 of Sheet1. Do you want to format the date a specific way or just use the system default?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Valued Forum Contributor GuruWannaB's Avatar
    Join Date
    01-24-2008
    Location
    55 miles S.E. of the Buckeye Capital!! Go BUCKS!!
    MS-Off Ver
    2003
    Posts
    382

    Re: Parsing Data Strings into Columns

    Actually...for convenient sake...I start the data on row 2...that way when it is parsed out, it will also be on row 2. The date is ok either way...its manipulated elsewhere.

  6. #6
    Valued Forum Contributor
    Join Date
    04-01-2009
    Location
    Irvine, CA
    MS-Off Ver
    Excel 2007
    Posts
    214

    Re: Parsing Data Strings into Columns

    Data --> Text to Columns will do what you want.
    If you want a macro (VBA code) to do it, then just record a macro of Text to Columns and change the ranges for variables.

  7. #7
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777

    Re: Parsing Data Strings into Columns

    Sub x()
        Dim astr() As String
        Dim cell As Range
        
        With Worksheets("Sheet1")
            For Each cell In .Range("A2", .Cells(.Rows.Count, "A").End(xlUp))
                astr = Split(cell.Text, ",")
                Worksheets("Sheet2").Cells(cell.Row, "A").Resize(, UBound(astr) + 1) = astr
            Next cell
        End With
    End Sub
    Last edited by shg; 05-04-2009 at 04:48 PM.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Valued Forum Contributor GuruWannaB's Avatar
    Join Date
    01-24-2008
    Location
    55 miles S.E. of the Buckeye Capital!! Go BUCKS!!
    MS-Off Ver
    2003
    Posts
    382

    Re: Parsing Data Strings into Columns

    SHG

    This works great...however I am losing two columns of data somewhere. When I run the macro...it works, but only goes to column AV when I've got enough data to go over to column AX.

    Chance2,

    You taught me something new...but I am looking for a macro that I can bastardize abit - thanks however. I might rethink my processes to work with this newfound knowledge as a backup however.

  9. #9
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777

    Re: Parsing Data Strings into Columns

    Oops. Try again.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Valued Forum Contributor GuruWannaB's Avatar
    Join Date
    01-24-2008
    Location
    55 miles S.E. of the Buckeye Capital!! Go BUCKS!!
    MS-Off Ver
    2003
    Posts
    382

    Re: Parsing Data Strings into Columns

    Bloody Brilliant!

    Thank you so much!

    Now take the rest of the day off!!! PAID

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Parsing Data Strings into Columns

    Hello GuruWannaB,

    This will convert Sheet1's data into separate columns on Sheet2.
    Sub ConvertToColumns()
    
      Dim DstRng As Range
      Dim LastRow As Variant
      Dim R As Long
      Dim SrcRng As Range
      
        Set SrcRng = Worksheets("Sheet1").Range("A2")
          LastRow = SrcRng.Parent.Cells(Rows.Count, "A").End(xlUp).Row
          LastRow = IIf(LastRow < SrcRng.Row, SrcRng.Row, LastRow)
          Set SrcRng = SrcRng.Parent.Range("A2:A" & LastRow)
          
        Set DstRng = Worksheets("Sheet2").Range("A2")
        Set DstRng = DstRng.Resize(SrcRng.Rows.Count, 1)
        SrcRng.Copy Destination:=DstRng
        
        DstRng.Parent.Activate
        DstRng.TextToColumns Comma:=True
        
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  12. #12
    Valued Forum Contributor GuruWannaB's Avatar
    Join Date
    01-24-2008
    Location
    55 miles S.E. of the Buckeye Capital!! Go BUCKS!!
    MS-Off Ver
    2003
    Posts
    382

    Re: Parsing Data Strings into Columns

    Thank you Leith...this gives me something more to work with...!

+ 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.2.0