VBA code to exclude macro performing on specified worksheet

mrexcelhelp123

New Member
Joined
Mar 10, 2010
Messages
38
Can someone help me find out what is wrong with this code? I need some changes made on all worksheets (except the ones listed) for all open workbooks.

Code:
Sub Step2_Modify_Summary_Tabs()
Dim wb As Workbook
Dim ws As Worksheet
 
For Each wb In Workbooks
 
    For Each ws In Worksheets
    
    If ws <> "Sheet1" _
    Or ws <> "Sheet2" _
    Or ws <> "Sheet3" _

    Then
 
    .Range("A1:A2").ClearContents
 
    End If
    Next ws
    
Next wb
    
End Sub
 
Let's say that the sheet you want to exclude is named "Sheet1", try...

Code:
[COLOR=darkblue]Sub[/COLOR] Fixed_Assets_Recons()

    [COLOR=darkblue]Dim[/COLOR] xsheet [COLOR=darkblue]As[/COLOR] Worksheet
    
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] xsheet [COLOR=darkblue]In[/COLOR] ThisWorkbook.Worksheets
        [COLOR=darkblue]If[/COLOR] xsheet.Name <> "Sheet1" [COLOR=darkblue]Then[/COLOR]
            [COLOR=green]'etc[/COLOR]
            '
            [COLOR=green]'[/COLOR]
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]Next[/COLOR] xsheet
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Change the sheet name accordingly.

Hope this helps!
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I'm having an issue with the "If WS.Name <> "Sheet1" code. It doesn't seem to be working for me. Below is what I've done, but it does not exclude sheet 1.

Does anyone have any thoughts?

Dim WS As Worksheet
Dim Starting_WS As Worksheet


For Each WS In ThisWorkbook.Worksheets
If WS.Name <> "Sheet1" Then
WS.Activate
Range("A1:D1", Range("C1").End(xlToRight)).Interior.Color = rgbDarkMagenta

'ALL CODE GOES WITHIN HERE


End If
Next WS
 
Upvote 0

Forum statistics

Threads
1,215,222
Messages
6,123,704
Members
449,118
Latest member
MichealRed

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top