Identifying Multiple Selected Worksheets

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm trying to create a macro that will only affect the worksheets that are currently selected (when a user uses ctrl+click on multiple worksheet tabs). How do I identify which worksheets are selected in VBA?

Thank you very much,
-David
 
This code shows a message box for each selected worksheet in the workbook:

For Each sh In Workbooks("BOOK2.XLS").Windows(1).SelectedSheets
MsgBox sh.Name
Next

HTH

--
Michael J. Malinsky
Pittsburgh, PA

"I am a bear of very little brain, and long
words bother me." -- AA Milne, Winnie the Pooh

DavidMatthews said:
Hi,

I'm trying to create a macro that will only affect the worksheets that are
currently selected (when a user uses ctrl+click on multiple worksheet tabs).
How do I identify which worksheets are selected in VBA?
 
Hi David

You can loop through them like this

Sub test()
Dim sh As Worksheet
For Each sh In ActiveWindow.SelectedSheets
MsgBox sh.Name
Next
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


DavidMatthews said:
Hi,

I'm trying to create a macro that will only affect the worksheets that are currently selected (when a user uses ctrl+click on
multiple worksheet tabs). How do I identify which worksheets are selected in VBA?
 

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