Paste to end of data

mholme58

New Member
Joined
Jul 27, 2010
Messages
40
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
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

mrshl9898

Well-known Member
Joined
Feb 6, 2012
Messages
1,549
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
 

mholme58

New Member
Joined
Jul 27, 2010
Messages
40
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.
 

mrshl9898

Well-known Member
Joined
Feb 6, 2012
Messages
1,549
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
 

Watch MrExcel Video

Forum statistics

Threads
1,118,808
Messages
5,574,433
Members
412,592
Latest member
moonsugar
Top