You do not have to do copy it to the cell and then use Text-To-Columns on it, you can do it directly...I need a macro that would copy some data from say A1 on Sheet 1, then paste it on A1 on Sheet 2, then perform a text to column, delimited by space.
Is this possible? Thanks a lot
Sub CopyAndSplit()
Dim Words() As String
Words = Split(Sheets("Sheet1").Range("A1").Value)
Sheets("Sheet2").Range("A1").Resize(, UBound(Words) + 1).Value = Words
End Sub
Code:Sub CopyAndSplit() Dim Words() As String Words = Split(Sheets("Sheet1").Range("A1").Value) Sheets("Sheet2").Range("A1").Resize(, UBound(Words) + 1).Value = Words End Sub
You did not mention these were numbers in your original message and since you were using Text-To-Columns, I assumed they were text. Try this modification to my code and see if it works for you...Rick, this is great, only as it is a set of numbers, not words, the numbers are stored as words, and the fomulas now do not work. Is there a way to change it?
Sub CopyAndSplit()
Dim Words As Variant
Words = Split(Sheets("Sheet1").Range("A1").Value)
With Sheets("Sheet2").Range("A1").Resize(, UBound(Words) + 1)
.Value = Words
.Value = .Value
End With
End Sub
That works perfectly, thanks for your time.Code:Sub CopyAndSplit() Dim Words As Variant Words = Split(Sheets("Sheet1").Range("A1").Value) With Sheets("Sheet2").Range("A1").Resize(, UBound(Words) + 1) .Value = Words .Value = .Value End With End Sub
I think this does what you want...Rick, is it possible to edit this formula so that it copies-and-splits every value in the A column? And puts them on their respective Sheet 2 row?
Sorry to bother you, thanks for your time!
Sub CopyAndSplit()
Dim Words As Variant, Cell As Range
For Each Cell In Sheets("Sheet1").Range("A1", Cells(Rows.Count, "A").End(xlUp))
Words = Split(Cell.Value)
With Sheets("Sheet2").Range(Cell.Address).Resize(, UBound(Words) + 1)
.Value = Words
.Value = .Value
End With
Next
End Sub
Just the job! Thanks a lotCode:Sub CopyAndSplit() Dim Words As Variant, Cell As Range For Each Cell In Sheets("Sheet1").Range("A1", Cells(Rows.Count, "A").End(xlUp)) Words = Split(Cell.Value) With Sheets("Sheet2").Range(Cell.Address).Resize(, UBound(Words) + 1) .Value = Words .Value = .Value End With Next End Sub