Looping only through selected sheets

  • Thread starter Thread starter Paul S
  • Start date Start date
P

Paul S

What is the VBA code to loop through only the selected sheets in a workbook?
That is if I have a workbook contain sheets A, B, C, D, and E and if I have
selected multiple sheets, say A, B and E, how do I write code that will
perform operations only on those sheets (A, B, and E)?
 
dim sh as object 'could be a chart sheet???
for each sh in activewindow.selectedsheets
msgbox Sh.name
next sh
 
Hi,

Try this

Dim sh As Object
For Each sh In ActiveWindow.SelectedSheets
MsgBox sh.Name
'do things
Next

Mike
 
Thanks. Did not think of using the Window object. Though it should be in
the Workbook object.
 
But you could have multiple windows into the same workbook. And each window
could have different sheets selected.

What would you use?
 

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