ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   determine what sheet user is viewing (https://www.excelbanter.com/excel-programming/278114-determine-what-sheet-user-viewing.html)

Elias

determine what sheet user is viewing
 
This is probably very simple.

How can I make VBA know what sheet the user is viewing at the time they
activate a macro?

For instance, if they are looking at sheet 17, I want the macro's dialog box
to customize itself to limit its choices to those relevant to sheet 17. I
can do the customization, but don't know the 'if worksheet 17 is active
then...' command.

Thanks.



TroyW

determine what sheet user is viewing
 
If ActiveSheet.Name = "theName" Then
-or-
If ActiveSheet.CodeName = "theName" Then

Will serve your purpose.

The ".Name" property will give the name that is displayed on the SheetTab.
The ".CodeName" property will give the internal name of the sheet (e.g.
Sheet1, Sheet2, etc.), which can't be changed by the user. If the user
happens to rename the sheet, your macro will probably break if you use
".Name".

Troy

"Elias" wrote in message
...
This is probably very simple.

How can I make VBA know what sheet the user is viewing at the time they
activate a macro?

For instance, if they are looking at sheet 17, I want the macro's dialog

box
to customize itself to limit its choices to those relevant to sheet 17. I
can do the customization, but don't know the 'if worksheet 17 is active
then...' command.

Thanks.






All times are GMT +1. The time now is 06:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com