how to track named ranges in chart

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
see my reply with attached file at: named range tracking via VB

Code:
Sub vbax_52434_ChartSeriesSourceData()

    Dim wbNamedRanges()
    Dim cht As ChartObject
    Dim SeriesFormula As String, SeriesAddress As String, SeriesRange As String
    Dim i As Long
    
    With ThisWorkbook
        Select Case .Names.Count
            Case Is = 0
                MsgBox "There are no named ranges in this workbook!"
                Exit Sub
            Case Else
                ReDim wbNamedRanges(1 To .Names.Count)
                For i = 1 To .Names.Count
                    wbNamedRanges(i) = .Names(i).Name
                Next i
        End Select
    End With
    
    Set cht = Worksheets(1).ChartObjects(1) 'sample chart: named range
    'Set cht = Worksheets(1).ChartObjects(2) 'sample chart: not named range
    
    For i = 1 To cht.Chart.SeriesCollection.Count
        SeriesFormula = cht.Chart.SeriesCollection(i).Formula
        SeriesAddress = Split(SeriesFormula, ",")(2) '3rd bit in series formula
        SeriesRange = Mid(SeriesAddress, InStr(SeriesAddress, "!") + 1) 'remove wb/ws referenece
        If UBound(Filter(wbNamedRanges, SeriesRange)) > -1 Then
            MsgBox "Chart: " & cht.Name & " / Series: " & cht.Chart.SeriesCollection(i).Name & " / Source Data: " & Filter(wbNamedRanges, SeriesRange)(0) & " / Named Range"
        Else
            MsgBox "Chart: " & cht.Name & " / Series: " & cht.Chart.SeriesCollection(i).Name & " / Source Data: " & SeriesRange & " / Not Named Range!"
        End If
    Next

End Sub
 
Upvote 0
Hi mancubus,

This works great. Just one tweak to this, what if i want to find if the given named range is used within a chart. I mean in multiple sheets there are named ranges, and say if i want to find one of the named ranges to check if its used in chart, how to go about this in VBA?

Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

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