WB to WB Copy-Paste Error

Nurzhan

Board Regular
Joined
Dec 13, 2017
Messages
60
Hallo. This is a simple copy paste task but VBA makes me crazy with errors. Where is my mistake? The task is to copy a range of cells from WBb to WBa. Both of WBs are open.
Code:
Sub GasRate()Dim WBa As Workbook
Dim WBb As Workbook
Dim lastRow As Integer


Set WBa = Workbooks("GL Rates Calculation.xlsm") 
Set WBb = Workbooks("DPR_ALS_June_2018.xlsm") 


WBb.Sheets("Gas Balance").Cells(Rows.Count, "AC").End(xlUp).Row.Resize(-15).Copy         <===Error "424", object required here.
WBa.Sheets("GL").Range("N5").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False


End Sub
 

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"
Where is my mistake?
1. WBb.Sheets("Gas Balance").Cells(Rows.Count, "AC").End(xlUp).Row is just a number, not a range so it cannot be resized.

2. Even if the first part was a range, the first argument in Resize() is how many rows the new range will contain. A range cannot contain a negative number of rows.

Can you tell us in words what range in WBb you are actually trying to copy?
 
Upvote 0
Thanks Peter_SSs! The idea is to to find the last row in column AC and resize it for 15 rows up then copy that range. This range location will be dymanic but in the same column, will be moving downwards on daily basis. For example cuurent range = AC10:AC25.
 
Upvote 0
OK, then try this (untested at my end)
Code:
WBb.Sheets("Gas Balance").Cells(Rows.Count, "AC").End(xlUp).Offset(-14).Resize(15).Copy
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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