VBA Copy & Paste (with last row function)

mtjanousek

New Member
Joined
Jul 25, 2018
Messages
17
Hello,
I am trying to copy & paste values in column A from sheet 2 to sheet 3 and I want to copy all values starting with A2 till the end.

I was looking for a solution but without much success. I assume that the mistake is in selection of sheets. So far I have this:

Code:
Sub ExampleTest()

    Dim lr As Long
    Application.ScreenUpdating = False
    
'   Find the last used row in Column A of Sheet 2
    With Worksheets("Sheet2")
        lr = .Cells(Rows.Count, "A").End(xlUp).Row
    End With
    
        Sheets("Sheet2").Range("A2:A" & lr).Value = Sheets("Sheet3").Range("A2:A").Value
        
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Code:
Sub ExampleTest()
Dim lr As Long
With Worksheets("Sheet2")
    lr = .Cells(Rows.Count, "A").End(xlUp).Row
    Sheets("Sheet3").Range("A2:A" & lr).Value = .Range("A2:A" & lr)
End With
End Sub
 
Upvote 0
Thanks, I already tried something similar before but the problem is that nothing happens, Sheet3 stays empty.
 
Upvote 0
Yes, I copy pasted your code. I also tried another excel workbook wherein sheet 2 I wrote random values in column A starting with the second row, then applied the macro. Sheet 3 stayed empty.
 
Upvote 0
Code:
Sub ExampleTest()
Dim lr As Long
With Worksheets("Sheet2")
    lr = .Cells(Rows.Count, "A").End(xlUp).Row
    Sheets("Sheet3").Range("A2:A" & lr).Value = .Range("A2:A" & lr).Value
End With
End Sub
 
Upvote 0
This is great. Quick question, let's say I want to copy Column C in Sheet2 and place in Column A in Sheet3, how can I accommodate this with the above code? Thanks.

frank
 
Upvote 0
This is great. Quick question, let's say I want to copy Column C in Sheet2 and place in Column A in Sheet3, how can I accommodate this with the above code? Thanks.

frank
Code:
Sub ExampleTest()
Dim lr As Long
With Worksheets("Sheet2")
    lr = .Cells(Rows.Count, [COLOR=#ff0000]"C"[/COLOR]).End(xlUp).Row
    Sheets("Sheet3").Range("A2:A" & lr).Value = .Range([COLOR=#ff0000]"C2:C"[/COLOR] & lr).Value
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,528
Messages
6,125,342
Members
449,218
Latest member
Excel Master

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