ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excluding sheet from group of selected sheets (https://www.excelbanter.com/excel-programming/318179-excluding-sheet-group-selected-sheets.html)

Jack Sheet

Excluding sheet from group of selected sheets
 
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.

--
Return email address is not as DEEP as it appears



Jan Karel Pieterse

Excluding sheet from group of selected sheets
 
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



All times are GMT +1. The time now is 05:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com