PC Review


Reply
Thread Tools Rate Thread

ActiveSheet test

 
 
Gustaf
Guest
Posts: n/a
 
      15th Apr 2008
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 With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      15th Apr 2008
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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use a password in VBA ActiveSheet.protect & ActiveSheet.unprotect? Jim K. Microsoft Excel Programming 2 2nd Jun 2008 08:09 PM
Copying new activesheet after other activesheet is hidden? Simon Lloyd Microsoft Excel Programming 1 20th Jun 2006 10:02 AM
separating test data from test code + creating skeleton unit test classes QA Guy Microsoft C# .NET 0 6th Apr 2005 10:00 AM
separating test data from test code + creating skeleton unit test classes qualityassurance@gmail.com Microsoft C# .NET 0 6th Apr 2005 09:38 AM
VBA "IF" True/False test for ActiveSheet Protection Dennis Microsoft Excel Misc 4 15th Mar 2004 05:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:58 PM.