VBA: Detecting multiply selected sheets

B

Blargleman

Hi there.

Hopefully someone can help me with this, cause I can't seem to find any way
to do it...

I am trying to write a bit of code that will cycle through only the sheets
that I have previously selected by clicking on their tabs (holding down
'ctrl' as if selecting multiple sheets to print) then do <something> with
each of these selected sheets, ignoring the others in the workbook. I'll be
stuffed if I can see how to do it though! :(

Any suggestions??

Cheers all!
Glen
 
J

J.E. McGimpsey

One way:

Dim wkSht As Worksheet
For Each wkSht in ActiveWindow.SelectedSheets
'Do something
Next wkSht
 
D

Dave Peterson

One way:

Option Explicit
Sub testme01()

Dim wks As Worksheet

For Each wks In ActiveWindow.SelectedSheets
MsgBox wks.Name
Next wks

'and to delete them
With ActiveWindow.SelectedSheets
If .Count = .Parent.Sheets.Count Then
MsgBox "Can't delete all of them"
Else
Application.DisplayAlerts = False
.Delete
Application.DisplayAlerts = True
End If
End With

End Sub
 
B

Blargleman

Cheers!

That does the job nicely!

Thanks a lot

J.E. McGimpsey said:
One way:

Dim wkSht As Worksheet
For Each wkSht in ActiveWindow.SelectedSheets
'Do something
Next wkSht
 

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

Top