Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate mean of test scores from rows of test answers RiotLoadTime Excel Discussion (Misc queries) 1 July 26th 06 05:14 PM
Copying new activesheet after other activesheet is hidden? Simon Lloyd[_790_] Excel Programming 1 June 20th 06 10:02 AM
activesheet Jim at Eagle Excel Programming 1 April 6th 05 12:21 AM
name of the activesheet rasta Excel Programming 1 October 3rd 03 09:49 PM
ActiveSheet Ron de Bruin Excel Programming 0 July 29th 03 04:59 PM


All times are GMT +1. The time now is 10:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"