determine what sheet user is viewing

E

Elias

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.
 
T

TroyW

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top