Is this code right?

usmrncrps

New Member
Joined
Feb 17, 2015
Messages
44
I'm looking to see if this line is correct?
My desired effect is to have Cell A2 of the Equipment Sheet or Sheet1 to be inserted at the bottom of a continuous list on the Graph Sheet or Sheet2.

Sheets ("WsEquipment").Range ("A2").Copy Destination:=Sheets ("WsGraphs").Range("Date").End(xlDown).Offset(1, 0)
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
It might be fine as-is...

But typically when specifying the next available row to paste something I prefer to start at the bottom of the sheet and work up. Your code might be OK, if the target paste sheet is already populated with data. However, if you clear it out, you might find that your code wants to try to paste info to the last cell on the worksheet offset by an additional row, which is impossible.

I also prefer to let the code determine what is the last possible row of a worksheet as the starting point. This is based on my prior experience developing code in older versions of excel that did not have so many rows. I hardcoded 65536 as the last row in some old macros that would be nowhere near the last row of a worksheet in modern versions of Excel.

So if it were me; my code might look like...
Code:
    Dim PasteSht As Worksheet
    Set PasteSht = Sheets("WsGraphs")

    
    Dim TargCol As Double
    TargCol = Range("Date").Column

    Sheets("WsEquipment").Range("A2").Copy Destination:=PasteSht.Cells(PasteSht.Rows.CountLarge, TargCol).End(xlUp).Offset(1, 0)
 
Upvote 0

Forum statistics

Threads
1,196,280
Messages
6,014,438
Members
441,819
Latest member
Blackov

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