Very simple

  • Thread starter Thread starter Aaron Cooper
  • Start date Start date
A

Aaron Cooper

This has got to be one of the easiest questions ever asked. I'm trying
to add a loop ( a For each loop) to a macro that will perform the macro
on all but one worksheet in the current workbook. The only worksheet
that I do not what it to run on will always have the same name, but the
sheets that I want the macro to run on will not always be the same.

Can anyone help?

Thanks.

Aaron
 
Aaron,

Try some code like the following:

Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
If StrComp(WS.Name, "do_not_process") <> 0 Then
' do something with WS
End If
Next WS

This will do something with every worksheet except the one named
"do_not_process".


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
For i = 1 to sheets.count
if worksheets(i).name <> "YourSheetNameToExclude" then
'run your macro...which must refer to worksheets(i)
end if
next
 

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