to return range variable without activating a sheet

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824
Plese see the following trivial macro

Code:
Public dest As Range
 Sub test()
 Set dest = Range("a1").End(xlDown)
With Worksheets("sheet3")
MsgBox dest.Address
End With
End Sub



this gives the dest.address of only the activesheet even though I have indicated it should be that of sheet3.

is it possible to get the dest. address of sheet3 without activating sheet3
if so how is the macro to be modified.? Thanks.
venkat
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try

Code:
Public dest As Range
Sub test()
Set dest = Sheets("Sheet3").Range("a1").End(xlDown)
MsgBox dest.Address
End Sub
 
Upvote 0
OGII
sorry I did not explain correrctly
iIwant to have the code statements so tht I can change the worksheetname in the 4th line in my macro to get the dest for that sheet without activating it.
venkat
 
Upvote 0
Code:
Public dest As Range
Sub test()
With Worksheets("sheet3")
   Set dest = .Range("a1").End(xlDown)
End With
MsgBox dest.Address
End Sub

Is this what you want?
 
Upvote 0
jindon thank you

that means I have to everytime set dest . I understnad.

venkat

I don't understand what you are after...

Because dest is a global object variable, it holds the reference until you change...
 
Upvote 0

Forum statistics

Threads
1,214,494
Messages
6,119,880
Members
448,926
Latest member
Geoexeng

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