Paste to end of data

mholme58

New Member
Joined
Jul 27, 2010
Messages
44
Hi, I have this macro that where I need to move data from across the sheet to the end of the data in column A.

The row mark ** is where it is falling down.

After the 'Selection.Delete Shift:=xlToLeft' I need to loop the copy ans paste 16 times. As I'm not a macro expert I'll probably repeat the code 16 times, but if anyone has a better idea?

Sub Format_csv()
'
' Format_csv Macro
'

'
Columns("A:A").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Columns("E:E").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("A:A").Select
Selection.Copy
Columns("E:E").Select
ActiveSheet.Paste
Rows("1:1").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Range("E1:F1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.ClearContents
Range("A1").Select
Range("E2:H2").Select
**Range("A" & Rows.Count).End(xlUp).Offset(1, 0)**
ActiveSheet.Paste
Columns("F:H").Select
Range("F22").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("E29").Select
Selection.End(xlUp).Select
Range("A1").Select
End If
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
What are you doing with that line? In plain english? You're pasting after it but not copying it seems.

VBA Code:
Sub Format_csv()

Columns("A:A").Delete Shift:=xlToLeft
Columns("E:E").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("A:A").Copy Columns("E:E")
Rows("1:1").Delete Shift:=xlUp
Range("E1").Select
Range(Selection, Selection.End(xlToRight)).ClearContents
Range("E2:H2").Select


''**Range("A" & Rows.Count).End(xlUp).Offset(1, 0)**
ActiveSheet.Paste
Columns("F:H").Select
Range("F22").Activate
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("E29").Select
Selection.End(xlUp).Select
Range("A1").Select

End Sub
 
Upvote 0
With the line that is going wrong, I have copied the data in columns E:H - which, as you point out, I have not pasted in here somehow!
So what I am trying to do is copy that data, and then paste it in the first blank cell in column A. I then want to repeat that 16 times.
 
Upvote 0
How's this looking?

VBA Code:
Sub Format_csv()

Dim ws As Worksheet
Dim lastrow As Long

Set ws = ActiveSheet

Columns("A:A").Delete Shift:=xlToLeft
Columns("E:E").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("A:A").Copy Columns("E:E")
Rows("1:1").Delete Shift:=xlUp
Range("E1").Select
Range(Selection, Selection.End(xlToRight)).ClearContents
lastrow = ws.Cells(ws.Rows.Count, "I").End(xlUp).Row
Range("E2:H2").Copy Range("E2:H" & lastrow)
Columns("F:H").Delete Shift:=xlToLeft
Range("E29").Select
Selection.End(xlUp).Select
Range("A1").Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,213
Members
448,554
Latest member
Gleisner2

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