How to check if Chart Exist in Current Sheet

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi, currently 'm using the code below, however i do not want to use error to check if chart exists in the sheet.
Please suggest better code. I just want to check if chart exist in active sheet irrespective of any name...

thanks in advance
Code:
[FONT=Courier New][FONT=Courier New]Option Explicit
Public chartexist As Boolean
[/FONT][/FONT]Sub CheckIfChartExist()
    On Error GoTo Err1
    ActiveSheet.ChartObjects(1).Activate
    chartexist = True
    Range("A1").Select
    Exit Sub
Err1:
    chartexist = False
    Err.Clear
End Sub
Sub TestFunction()
CheckIfChartExist
If chartexist = False Then
MsgBox "False"
Else
MsgBox "True"
End If
End Sub
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi, :)

maybe with this code:

Code:
Option Explicit
Sub Main()
    If fncChartExist Then
        MsgBox "Yes!"
    Else
        MsgBox "No!"
    End If
End Sub
Function fncChartExist() As Boolean
    Dim shpShape As Shape
    For Each shpShape In ActiveSheet.Shapes
        If shpShape.Type = msoChart Then fncChartExist = True: Exit Function
    Next shpShape
End Function
 
Upvote 0
Code:
Function SomeChartExists(Optional onWorksheet as Worksheet) As boolean
    If onWorksheet Is Nothing then Set onWorksheet = ActiveSheet
    
    SomeChartExits = Not(onWorksheet.ChartObjects.Count = 0)
Exit Function
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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