Copy Paste VBA Erroring Out

WWII_Buff

Board Regular
Joined
Nov 13, 2017
Messages
88
Can anyone tell me why this isn't running please?

Thanks in advance!

Code:
Sub Upload()

    Dim src As Worksheet
    Dim trg As Worksheet
    Dim LastRow As Long

    Set src = ThisWorkbook.Worksheets("MASTER")
    Set trg = ThisWorkbook.Worksheets("UPLOAD TEMPLATE")

    src.Range("A5:A" & LastRow).Copy Destination:=trg.Range("A6")
    src.Range("B5:B" & LastRow).Copy Destination:=trg.Range("B6")
    src.Range("AM5:AY" & LastRow).Copy Destination:=trg.Range("C6")

End Sub
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
"Isn't running" is not very helpful ...

Some clever programmer once said something like
An effective way of debugging is to minimize your (failing) application as much as you can. In this process you will often find the reason for the error.

So, make a copy of your program and with the copy, take off all code not needed and step through the few lines of code remaining until you can isolate the error.
This is also useful if you want to post your code. Small and easy to overview.
 
Upvote 0
Dim just tells the system which type of data to expect. Try this:

Code:
Sub Upload()

    Dim src As Worksheet
    Dim trg As Worksheet
    Dim LastRow As Long


    Set src = ThisWorkbook.Worksheets("MASTER")
    Set trg = ThisWorkbook.Worksheets("UPLOAD TEMPLATE")
    
[B]    LastRow = src.Cells(Rows.Count, 1).End(xlUp).Row[/B]


    src.Range("A5:A" & LastRow).Copy Destination:=trg.Range("A6")
    src.Range("B5:B" & LastRow).Copy Destination:=trg.Range("B6")
    src.Range("AM5:AY" & LastRow).Copy Destination:=trg.Range("C6")


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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