Recognizing a Chart Worksheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a macro that performs a function on each sht of a workbook. However,
I'd like it to skip Chart sheets. How can I test that a sheet is a chart so
that an If statement will not process that sheet?
 
Use an Excel.Worksheet object and ThisWorkbook.Worksheets collection.
This does not contain charts.

Another way would be using a method that charts don't have (like
Range) and testing for error - something along the lines of this:

Public Sub testForChart()
Dim wsh As Object
Dim i As Variant

For Each wsh In Excel.Sheets
On Error Resume Next
i = wsh.Range("A1").Value

If Err.Number <> 0 Then
Debug.Print "Skipping chart: " & wsh.Name
Err.Clear
Else
Debug.Print wsh.Name
End If
On Error GoTo 0
Next wsh
End Sub
 
Declare a variable as a worksheet, then loop through the worksheets
collection:

Dim WS As Worksheet
For Each WS In ActiveWorkbook.Worksheets
etc.

- Jon
 
Back
Top