Copy and paste vba need help

bryanalmeida525

New Member
Joined
Dec 12, 2017
Messages
12
Code:
Sub STEP2()


Dim Lastrow As Long
Dim Lastrow2 As Long
Dim Lastrow3 As Long
Dim Lastrow4 As Long
Dim Lastrow5 As Long
Dim Lastrow6 As Long






Application.ScreenUpdating = False


With Sheets("amir")
    Lastrow = .Cells(Rows.Count, 2).Row
    Lastrow2 = .Cells(Rows.Count, 7).Row
    Lastrow3 = .Cells(Rows.Count, 17).Row
    Lastrow4 = .Cells(Rows.Count, 22).Row
    End With


    
With Sheets("Entry")
    Lastrow5 = .Cells(Rows.Count, 1).Row
    Lastrow6 = .Cells(Rows.Count, 8).Row
    End With


    
    Sheets("amir").Range("B4:B" & Lastrow).copy
    Sheets("Entry").Range("A7").PasteSpecial xlPasteValues
    Sheets("amir").Range("B4:B" & Lastrow).copy
    Sheets("Entry").Range("A" & Lastrow5).PasteSpecial xlPasteValues
    Sheets("amir").Range("G4:G" & Lastrow2).copy
    Sheets("Entry").Range("H" & Lastrow6).PasteSpecial xlPasteValues
    Sheets("amir").Range("G4:G" & Lastrow2).copy
    Sheets("Entry").Range("H" & Lastrow6).PasteSpecial xlPasteValues

    
    Application.CutCopyMode = False
Application.ScreenUpdating = True




End Sub


** I Keep getting Run Time error 1004 Cant paste because the copy are and paste are aren't the same size.

Please help.
 
Last edited by a moderator:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
No i don't. Im just trying to copy the ranges and paste them over. I am trying to paste over each other.

I tried
Sheets("amir").Range("B4:B" & Lastrow).copy
Sheets("Entry").Range("A7" & Lastrow5).PasteSpecial xlPasteValues

But that didn't work. The second paste is supposed to go to the last row in the ENTRY sheet and paste it there.
 
Upvote 0
Lastrow range<> Lastrow5 range
make a variable su keep track of lastrow each time you paste. this value should be count after first paste
 
Upvote 0
You are calculating the last row incorrectly. this
Code:
Lastrow = .Cells(Rows.Count, 2).Row
will return either 65536, or 1048576 depending on version.
It should be like
Code:
lastRow = .Cells(Rows.Count, 2).End(xlUp).Row            'for the copy
lastRow5 = .Cells(Rows.Count, 1).End(xlUp).Offset(1).Row 'for the paste
And remove these 2 lines
Code:
    Sheets("amir").Range("B4:B" & Lastrow).copy
    Sheets("Entry").Range("A7").PasteSpecial xlPasteValues
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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