A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Limit Macro to Intended worksheet.



 
 
Thread Tools Display Modes
  #1  
Old March 2nd 07, 02:01 AM posted to microsoft.public.excel.worksheet.functions
Quin
external usenet poster
 
Posts: 37
Default Limit Macro to Intended worksheet.

Is there a way to limit a macro to work only on ONE work sheet? When I
record a macro I only see an option to store in a WORKBOOK but not a work
sheet.

The problem I have is my macro will distroy my worksheet if I hit the
shortcut key while the wrong worksheet tab is selected. With multiple macros
and multiple worksheets it is only a matter of time before I hit the shortcut
key and get unintended results!

Quin
Ads
  #2  
Old March 2nd 07, 02:08 AM posted to microsoft.public.excel.worksheet.functions
JE McGimpsey
external usenet poster
 
Posts: 4,624
Default Limit Macro to Intended worksheet.

one way:

Public Sub MyMacro
If ActiveSheet.Name <> "Safe" Then Exit Sub
'<rest of your macro here
End Sub

In article >,
Quin > wrote:

> Is there a way to limit a macro to work only on ONE work sheet? When I
> record a macro I only see an option to store in a WORKBOOK but not a work
> sheet.
>
> The problem I have is my macro will distroy my worksheet if I hit the
> shortcut key while the wrong worksheet tab is selected. With multiple macros
> and multiple worksheets it is only a matter of time before I hit the shortcut
> key and get unintended results!
>
> Quin

  #3  
Old March 2nd 07, 02:49 AM posted to microsoft.public.excel.worksheet.functions
Gord Dibben
external usenet poster
 
Posts: 22,912
Default Limit Macro to Intended worksheet.

Make your macro sheet-specific.

Sub MyMacro()
Sheets("Sheet1").Activate
run the code
End Sub

Or.........................

With Sheets("Sheet1")
run the code
End With

Or.....................

Use worksheet_activate code in the sheet module

Private Sub Worksheet_Activate()
MyMacro
End Sub

Note: this last one will run the macro everytime the sheet is selected. May
not be what you need.


Gord Dibben MS Excel MVP

On Thu, 1 Mar 2007 18:01:10 -0800, Quin > wrote:

>Is there a way to limit a macro to work only on ONE work sheet? When I
>record a macro I only see an option to store in a WORKBOOK but not a work
>sheet.
>
>The problem I have is my macro will distroy my worksheet if I hit the
>shortcut key while the wrong worksheet tab is selected. With multiple macros
>and multiple worksheets it is only a matter of time before I hit the shortcut
>key and get unintended results!
>
>Quin


 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
limit on size of macro for excell97 Joe Farruggio Excel Discussion (Misc queries) 1 September 18th 06 04:45 AM
limit size of worksheet abfabrob Excel Discussion (Misc queries) 7 February 22nd 06 05:04 PM
Worksheet Limit BillCPA Excel Discussion (Misc queries) 1 February 5th 06 05:19 AM
Worksheet Limit Jonathan Cooper Excel Discussion (Misc queries) 0 February 4th 06 08:07 PM
macro to time limit workbook ditchy Excel Discussion (Misc queries) 5 April 26th 05 08:43 AM


All times are GMT +1. The time now is 12:45 AM.


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