Selecting range in another workbook

telesien

New Member
Joined
May 25, 2016
Messages
35
This should normally work and I guess the problem would be with the "activecell" syntax, which creates problems since I refer to another workbook.

Any idea how to fix this so it works? Googled several questions, but didn't find this specific problem. It keeps returning '1004' error, Method 'Range' of object'_Wokrsheet' failed

Thanks

Code:
Dim WS as Worksheet
Dim DataRange as Range

Set WS = Workbook(name).Sheets(name)
Set DataRange = Range(Range("A2"), ActiveCell.SpecialCells(xlLastCell))

DataRange. select
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi,

Can you try this ?

Code:
Dim WS as Worksheet
Dim DataRange as Range

Set WS = Workbook(name).Sheets(name)
Set DataRange = WS.Range(WS.Range("A2"), WS.Range("A2").SpecialCells(xlCellTypeLastCell))

DataRange.Select

No need to use ActiveCell since SpecialCells(xlCellTypeLastCell) always returns the last cell used in the sheet.
 
Last edited:
Upvote 0
Hi,

Can you try this ?

Code:
Dim WS as Worksheet
Dim DataRange as Range

Set WS = Workbook(name).Sheets(name)
Set DataRange = WS.Range(WS.Range("A2"), WS.Range("A2").SpecialCells(xlCellTypeLastCell))

DataRange.Select

No need to use ActiveCell since SpecialCells(xlCellTypeLastCell) always returns the last cell used in the sheet.


Thanks, this did work. I am pretty sure I tried it as well, but I must have made some other mistake there, because it didn't :)
 
Upvote 0

Forum statistics

Threads
1,216,441
Messages
6,130,643
Members
449,585
Latest member
Nattarinee

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