Macro Copy/Paste then split column

CalvT

New Member
Joined
Dec 9, 2013
Messages
21
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
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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
You do not have to do copy it to the cell and then use Text-To-Columns on it, you can do it directly...

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
 
Upvote 0
Hi I hope it will help you....

Sub test()


Dim rng As Range
Dim sh As Worksheet
Dim Rcount As Integer


First.Range("A1").CurrentRegion.Copy Destination:=second.Range("A1")
Set sh = Worksheets(2)
With sh
Set rng = .Range("A1" & ":" & "a19")
Set rng = .Range(rng, .Cells(.Rows.Count, rng.Column).End(xlUp))
rng.TextToColumns Destination:=rng, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, _
FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
End With
End Sub

Warm Regards,

Vikas Verma
India.:cool:
 
Upvote 0
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

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?

Thanks
 
Upvote 0
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?
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...

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
 
Upvote 0
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
That works perfectly, thanks for your time.
Cheers
 
Upvote 0
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!
 
Upvote 0
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!
I think this does what you want...

Code:
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
 
Upvote 0
Code:
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 lot
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top