Excluding sheet from group of selected sheets

  • Thread starter Thread starter Jack Sheet
  • Start date Start date
J

Jack Sheet

Hi all
Have got this far

Dim sGroupedWS() As String
Dim lGroupedWSCount As Long
Dim lCounter As Long
lGroupedWSCount = ActiveWindow.SelectedSheets.Count
For lCounter = 1 To lGroupedWSCount
sGroupedWS(lCounter) = ActiveWindow.SelectedSheets(lCounter).Name
Next lCounter

Problem:
First I want to check whether the worksheet "HELP" is the only selected
sheet and if it is then exit sub.
Assuming that "HELP" is not the only selected sheet (and it may not even be
selected at all) then I want to exclude the worksheet "HELP" from the group
of selected sheets, ie unselect that particular sheet but otherwise leave
the selected sheets unchanged. If "HELP" was the activesheet then I do not
really care what sheet becomes the activesheet when "HELP" is unselected.

Overall intention is this (and there may be a better approach than the
above)
The macro deletes the selected sheets, which may be a group of selected
sheets. The only restriction that I wish to impose is that the worksheet
"HELP" must NOT be deleted if it is included in the group of selected sheets
(and it may not be included).

Any help gratefully received.
 
Hi Jack,
The macro deletes the selected sheets, which may be a group of selected
sheets. The only restriction that I wish to impose is that the worksheet
"HELP" must NOT be deleted if it is included in the group of selected sheets
(and it may not be included).

Like this maybe:

Dim oSh as Object
Application.DisplayAlerts=False
For Each oSh in Activewindow.SelectedSheets
If oSh.Name<>"HELP" Then
oSh.Delete
End If
Next
Application.DisplayAlerts=True

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top