Reference to selected cells in another worksheet.

Herakles

Well-known Member
Joined
Jul 5, 2020
Messages
927
Office Version
  1. 365
Platform
  1. Windows
Selection means ActiveWorkbook.ActiveSheet.Selection to Excel

How can I make reference to the selected cells in another worksheet without activating that worksheet.

Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi,

You can test
VBA Code:
Sub test()
MsgBox Sheet2.Range("A1").Value
End Sub
 
Upvote 0
Hi,

You can test
VBA Code:
Sub test()
MsgBox Sheet2.Range("A1").Value
End Sub
I probably did not make my self clear enough.

It is the address of the selected cells that I need and not the values contained within them.

For example if the cells A1:B5, D2:D7 and H7:H29 are selected I want to return the $A$1:$B$5,$D$2:$D$7,$H$7:$H$29 range.
 
Upvote 0
Sorry ... :(

For the addresses .... you can use Selection.Address
 
Upvote 0
But Selection means ActiveWorkbook.ActiveSheet.Selection to Excel.

The workbook and the sheet cannot be specified as they are part of Selection.

I have to activate the sheet to get the range of selected cells for that sheet.
 
Upvote 0
Since you seem not to be using variables ... would you mind posting your macro ... ;)
 
Upvote 0
How ever I do it, Selection still returns the selection in the active worksheet.

ActiveWorkbook.ActiveSheet.Selection is just a means of understanding its meaning.

I cannot even refer to the active cell in another sheet without that sheet being active.

VBA Code:
Public Sub subSelection()
Dim rng As Range

    MsgBox Selection.Address
    
    Set rng = Selection
    
    MsgBox rng.Address
    
End Sub
 
Upvote 0
You are right !!!
"I cannot even refer to the active cell in another sheet without that sheet being active" ...

By definition, Active does mean Active
For your general information, when working with macros, you do not need to use Active nor Activate ...

More importantly, can you explain what you want to accomplish ...
 
Upvote 0
I understand that the term Active should refer to the active sheet or workbook but having to
activate another worksheet in order to find the ActiveCell or Selection seems strange to me.

All I want to do is to loop through all areas / cells in the selected areas / cells in another worksheet.

It's not as if I cannot do it but I have to change active sheets and then change back again.

I just have to remember to disable and then enable events just in case the Activate and Deactivate events are set up.
 
Upvote 0
OK ...

In order to " loop through all areas / cells in the selected areas / cells in another worksheet " there is no need to Activate anything ...

Can you post your current macro ? or explain in plain English an example of a loop you do need ?
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,618
Members
449,092
Latest member
amyap

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