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.
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 Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Here's a generic example of the data strings.....
Hope that helps - thanks again
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 Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
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.
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.
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
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.
Oops. Try again.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Bloody Brilliant!
Thank you so much!
Now take the rest of the day off!!! PAID
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 Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Thank you Leith...this gives me something more to work with...!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks