Quick question regarding xlDown/xlToRight and .copy

Jnrrpg11

New Member
Joined
Jun 29, 2017
Messages
28
Hello Everyone,

Im trying to make my VBA code simpler and more efficient.

I am copy/pasting from one workbook called "ART" into the active workbook "FY Forecast Manager 2".
Previously i used the .Activate / .Select / .Selection.Copy method which worked.

Im trying to cut this code down to fewer lines now and the code i currently have is -


Sub ImportART()


Workbooks("Art.csv").Sheets("ART").Range("A1:BZ15000").Copy Sheets("FY Budget from ART").Range("A4")


End Sub


This code works but I've just stabbed at where the last row of the data will be (BZ15000).

In the select method i was using this code which worked -


Workbooks("ART.csv").Activate
Range("A1", Range("A1").End(xlToRight).End(xlDown)).Select
Selection.Copy


Workbooks("FYForecastManager2.xlsm").Activate
Worksheets("FY Budget from ART").Range("A4").PasteSpecial xlPasteValues



It seems when i try to combine the .End(xlToRight).End(xlDown) into the first sub it gives me a Runtime 1004 error.

Is it possible to use the first method and also use VBA to find the exact size of the data set?



Thanks in advance and Kind Regards

Richard
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
or for values only, what about?
Code:
With Workbooks("Art.csv").Sheets("ART").Range("A1")
    Sheets("FY Budget from ART").Range("A4").Resize(.Rows.Count, .Columns.Count).Value = .Value
End With
 
Upvote 0
Hello Fazza,

Thanks for taking the time to reply.
The first solution works perfectly, I've never seen the .CurrentRegion command before so this is going to be incredibly useful.


Thanks Again and Kind Regards

Richard
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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