I ran into a problem while trying to write a VBA code to copy the content of a column to another sheet in the same project. The problem is that instead of copying the entire columns' data it only copies the last row's data.
This is the VBA code I have. Thanks in advance.
Sub copycolumns()
Dim lastrow As Long, erow As Long
lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow 'this will iterate from the 2nd row, as first one is the header
Sheet1.Cells(i, 1).Copy 'copy value of first row i and column one
erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Sheet1.Paste Destination:=Worksheets("Sheet4").Cells(erow, 1)
'paste it on Sheet4's first empty row and column 1.
Sheet1.Cells(i, 4).Copy 'copy value of first row i and column 4
Sheet1.Paste Destination:=Worksheets("Sheet4").Cells(erow, 3)
'paste it on Sheet4's first empty row and column 3
Sheet1.Cells(i, 5).Copy 'copy value of first row i and column 5
Sheet1.Paste Destination:=Worksheets("Sheet4").Cells(erow, 2)
'paste it on Sheet4's first empty row and column 2
Sheet1.Cells(i, 8).Copy 'copy value of first row i and column 8
Sheet1.Paste Destination:=Worksheets("Sheet4").Cells(erow, 4)
'paste it on Sheet4's first empty row and column 4
Sheet1.Cells(i, 9).Copy 'copy value of first row i and column 9
Sheet1.Paste Destination:=Worksheets("Sheet4").Cells(erow, 5)
'paste it on Sheet4's first empty row and column 5
Next i 'go to the next row
'will implement this clean up commands after code works
'Application.CutCopyMode = False
'Sheet2.Columns.AutoFit
'Range("A1").Select
End Sub