VBA: Select Used Range

SteveOranjin

Board Regular
Joined
Dec 18, 2017
Messages
170
Hello,

I am attempting to write a macro that selects a used range, and pastes it into a new document. What I want the macro to do is move all the data that is in one sheet, into another. I don't want to copy the entire sheet though, as that is putting unneccessary stress on the computer.

Code:
Option Explicit
Sub Import() 'Excel VBA to Open a signle file and import data


'We are defining our variables.
Dim owb As Workbook
Dim Sh As Worksheet


Set Sh = Sheet1
'open a file called (england)
Set owb = Workbooks.Open("C:\Users\Data Coordinator I\Desktop\England\England")






owb.Sheets("Sheet1").Range("A1:F100").Copy
Sh.Range("A1").PasteSpecial xlPasteValues
owb.Close False




End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
1. Add a file extension to your owb file path.
2. owb.Sheets("Sheet1").UsedRange.Copy
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
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