PDA

View Full Version : Find Chart's Parent worksheet with given chart name



SP69
11-29-2012, 11:17 PM
Hi,
I am having workbook with 10-12 sheets, each containing 3-4 charts. I have chart name but not the associated sheet name. Do we have a direct function to find the worksheet name associated with chart?? Right now i am using below mentioned solution:



Function ReturnSheetNameOfChart(ChartName As String) As String
Dim cht As Chart
Dim sh As Worksheet
Dim strWbkName As String

For Each sh In ThisWorkbook.Sheets
On Error Resume Next
Set cht = sh.ChartObjects(ChartName).Chart
If Err.Number = 0 Then strWbkName = strWbkName & sh.Name & ","
Err.Clear: On Error GoTo 0
Next
ReturnSheetNameOfChart = Left(strWbkName, Len(strWbkName) - 1)
End Function

Any better and fast solution because this is timetaking to scan through each sheet.

littleiitin
11-30-2012, 09:23 AM
Hi SP69,

if you have chart name only and you want to get the worksheet name then only way is to navigate through all the sheets which you already did.

Thanks