Copy and paste columns without header to another sheet in same file

Ananthak275

Board Regular
Joined
Aug 22, 2020
Messages
128
Office Version
  1. 2013
Platform
  1. Windows
  2. MacOS
Need to copy columns starting from A3 till last row of data from Sheet1 to Sheet2.
  • the last row of the data changes every time. so it could be A3:A27 or A3:A9
  • On Sheet2 (the destination sheet name) the cell should be A2
Could this also be a loop so it does it from column A & B?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
This copies from the source row (srcrow) starting with A3 to the last used row (LastRow) on Sheet1 to B2 on Sheet2. Is this what you were looking for?

VBA Code:
Sub movesheet()
    Dim LastRow As Long
    Dim destrow As Long
        
    destrow = 2
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    
    For srcrow = 3 To LastRow            'start at row 3
        Worksheets("Sheet2").Range("B" & destrow) = Worksheets("Sheet1").Range("A" & srcrow)
        destrow = destrow + 1
    Next
End Sub
 
Upvote 0
I think I misunderstood something. I read that is was from column A to column B. I read it again and you want to copy both column A and B to Sheet2

VBA Code:
Sub movesheet()
    Dim LastRow As Long
    Dim destrow As Long
        
    destrow = 2
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    
    For srcrow = 3 To LastRow            'start at row 3
        Worksheets("Sheet2").Range("A" & destrow) = Worksheets("Sheet1").Range("A" & srcrow)
        Worksheets("Sheet2").Range("B" & destrow) = Worksheets("Sheet1").Range("B" & srcrow)
        destrow = destrow + 1
    Next
End Sub
 
Upvote 0
I think I misunderstood something. I read that is was from column A to column B. I read it again and you want to copy both column A and B to Sheet2

VBA Code:
Sub movesheet()
    Dim LastRow As Long
    Dim destrow As Long
       
    destrow = 2
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
   
    For srcrow = 3 To LastRow            'start at row 3
        Worksheets("Sheet2").Range("A" & destrow) = Worksheets("Sheet1").Range("A" & srcrow)
        Worksheets("Sheet2").Range("B" & destrow) = Worksheets("Sheet1").Range("B" & srcrow)
        destrow = destrow + 1
    Next
End Sub
I'm getting the error Compile error: Variable not defined for srcrow. There is another macro in this module
 
Upvote 0
You can add a "dim srcrow as long"

VBA Code:
Sub movesheet()
    Dim LastRow As Long
    Dim destrow As Long
    Dim srcrow As Long
        
    destrow = 2
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    
    For srcrow = 3 To LastRow            'start at row 3
        Worksheets("Sheet2").Range("A" & destrow) = Worksheets("Sheet1").Range("A" & srcrow)
        Worksheets("Sheet2").Range("B" & destrow) = Worksheets("Sheet1").Range("B" & srcrow)
        destrow = destrow + 1
    Next
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,827
Messages
6,121,823
Members
449,049
Latest member
cybersurfer5000

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