Macro to work only on selected worksheets

S

Skihde

Hi All,

I've got a macro that will paste a rectangle on a sheet. That's easy.
The hard part is that I want it to do that only across selected sheets
in a workbook, say sheets 1, 2, 5, 8, and 10 of 10sheets. I can get it
on one sheet at a time, as well as ALL the sheets in a workbook, just
not those specific ones. Any ideas?

Thanks in advance,
Stephan
 
G

Gord Dibben

Sub test()
Dim ws As Worksheet
Set MySheets = ThisWorkbook.Worksheets(Array("Sheet1", "Sheet2", "Sheet3"))
'or if you select the sheets with CTRL + Click
'Set MySheets = ActiveWindow.SelectedSheets
For Each ws In MySheets

'do your stuff

Next ws
End Sub


Gord Dibben MS Excel MVP
 

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