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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Public dest As Range
Sub test()
Set dest = Sheets("Sheet3").Range("a1").End(xlDown)
MsgBox dest.Address
End Sub
 

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824
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
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
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?
 

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824

ADVERTISEMENT

jindon thank you

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

venkat
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
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...
 

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824

ADVERTISEMENT

yes I understand.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,030
Messages
5,856,935
Members
431,841
Latest member
jaybeem

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
Top