Chart Exists Function


The following Function has been designed to check if a chart already exists in the open workbook. If it does exist then it will return TRUE, if not then the Function will return FALSE. Based on this function your other code can then create the chart if needed or use the existing chart.

Function ChartExists(cName As String, Optional oWb As Workbook) As Boolean
'Returns true if chart exists in the specified workbook.
'If no workbook supplied, the activeworkbook is used.

If oWb Is Nothing Then Set oWb = ActiveWorkbook

On Error Resume Next
ChartExists = CBool(Not oWb.Charts(cName) Is Nothing)
On Error GoTo 0

End Function

If you have a question on this post for the Excel Help Desk team or have something you would like to share on this topic then please leave a comment.