Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
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
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
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


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
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 06:04 PM
Worksheet Limit BillCPA Excel Discussion (Misc queries) 1 February 5th 06 06:19 AM
Worksheet Limit Jonathan Cooper Excel Discussion (Misc queries) 0 February 4th 06 09: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 11:56 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"