View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
AmyTaylor[_29_] AmyTaylor[_29_] is offline
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