LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default run macro on selected sheets only


Hi,
I have a macro which runs from a floating toolbar and allows the user
to delete the current worksheet they have open.
However, I only want it to run on certain sheets, and be disabled on
others.
Ideally, if the user tried to run it on a worksheet that they shouldnt
delete, something like a messagebox would appear and say "sorry, you
cant delete this sheet". otherwise it would run the delete macro.

I have the following macro already, but it spools thru all the
workbooks and so you need to click the messagebox a dozen times!

'Delete the current sheet
Sub Delete()
Set wkb = ActiveWorkbook
For Each wks In wkb.Worksheets
If Left(wks.Name, 1) = "S" Then
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
Else
MsgBox "Sorry, you cannot delete this sheet"
Set wkb = Nothing
End If
Next wks
End Sub

Any help gratefully received !

Amy xx


--
AmyTaylor
------------------------------------------------------------------------
AmyTaylor's Profile: http://www.excelforum.com/member.php...o&userid=20970
View this thread: http://www.excelforum.com/showthread...hreadid=469436

 
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
Macro to run on selected sheets terilad Excel Discussion (Misc queries) 18 April 7th 10 03:14 PM
How to run macro on selected sheets with one go? Harshad[_2_] Excel Discussion (Misc queries) 10 October 21st 08 10:35 AM
Protecting Macro and selected sheets ST Excel Discussion (Misc queries) 1 June 6th 06 03:03 PM
a for selected sheets print named page macro Todd Excel Programming 1 July 22nd 04 12:25 AM
Passing Selected Sheets' Names to a Macro John Tjia Excel Programming 5 December 24th 03 04:36 PM


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

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

About Us

"It's about Microsoft Excel"