Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
ActiveSheet test
This ought to be simple, but I can't find any working examples. I want to test that I'm on the right sheet, and if not exit the procedure. I've found the ActiveSheet property, but can't figure out how to use it. I'd like something like:
If ActiveSheet.Name < "Sheet1" Then Exit Sub I also wonder if there's ever a risk that code written in the Sheet1 module is ever run on another sheet? Perhaps what I want to do is never necessary? Gustaf |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
ActiveSheet test
Your idea is correct. For example:
Sub gustaf() If ActiveSheet.Name = "Sheet1" Then MsgBox ("we are on Sheet1") Else MsgBox ("we are on some other sheet") End If End Sub There are other ways of thinking about this issue. If you need the ActiveSheet to be Sheet1, you can just Activate it. You can also write your code to not depend on being on a specific sheet. For example, instead of: Range("A1").Value=123 use: Sheets("Sheet1").Range("A1").Value=123 -- Gary''s Student - gsnu200779 "Gustaf" wrote: This ought to be simple, but I can't find any working examples. I want to test that I'm on the right sheet, and if not exit the procedure. I've found the ActiveSheet property, but can't figure out how to use it. I'd like something like: If ActiveSheet.Name < "Sheet1" Then Exit Sub I also wonder if there's ever a risk that code written in the Sheet1 module is ever run on another sheet? Perhaps what I want to do is never necessary? Gustaf |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Calculate mean of test scores from rows of test answers | Excel Discussion (Misc queries) | |||
Copying new activesheet after other activesheet is hidden? | Excel Programming | |||
activesheet | Excel Programming | |||
name of the activesheet | Excel Programming | |||
ActiveSheet | Excel Programming |