Loop throguh sheets, perform actions on non-chart tabs

rdw72777

Well-known Member
Joined
Apr 5, 2005
Messages
723
I'm trying to loop through sheets and perform actions on those tabs that aren't chart tabs. However, in trying tod etermine if a tab is a chart tab or not i'm getting hung up.

The code is bombing on the "If cht = Nothing then" line. I'm not married to this solution so any other ideas/suggestions are appreciated.

Code:
SheetCount = wkb.Sheets.Count
    
    For q = SheetCount To 1 Step -1
        Sheets(q + 1).Select
        Set cht = ActiveChart
        
        If cht = Nothing Then
            Sheets(q).Cells(1, 1).Select
        End If
                
    Next q
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
The Sheets collection includes chart sheets, the Worksheets collection does not.

Code:
Dim oneWorkSheet as Worksheet

For Each oneWorksheet in ThisWorkbook.Worksheets
    Rem do stuff
Next oneWorksheet
 
Upvote 0
If you use Worksheets instead of Sheets that will exclude chart sheets. Something like

Code:
SheetCount = wkb.Worksheets.Count
For q = SheetCount To 1 Step -1
    Worksheets(q).Select
    Cells(1, 1).Select
Next q
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,253
Members
452,900
Latest member
LisaGo

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