I have a dashboard with multiple pivot charts. A macro controls chart formatting based on numerous criteria. The dataset is huge and frequently changes, so I want to update manually, as needed, on a per-chart basis rather than running on Worksheet_Calculate/_PivotTableUpdate/_PivotTableAfterValueChange/etc. (which would make everything intolerably slow).
The current macro iterates over ActiveChart, so I have to manually activate each chart before clicking the button. My question is: How can I activate the chart above/below/adjacent to the clicked button? I realize that I can make a separate macro for each chart that first activates the chart and then calls the main macro, but I'd much rather just have one script that can figure out the chart of interest based on the button location so it dynamically adapts to new charts/moved charts/changing chart names.
Sub UpdateChartAboveClickedButton ()
Dim wb as Workbook
Dim sht As Worksheet
Dim btn_clicked As String
Dim btn_location As Range
Dim cht_to_update As ChartObject
Set wb = myworkbook
Set sht = wb.myworksheet
btn_clicked = Application.Caller 'find clicked button
btn_location = sht.Shapes(btn_clicked).TopLeftCell.Address 'locate clicked button
---------------------------------------
cht_to_update = ??? 'find chart object directly above the clicked button
----------------------------------------
With cht_to_update
With .Format
[code...]
End With
End With
End Sub
(Also, if there's a better option than using the ApplicationCaller's .Address property, please say so. It was just the most straightforward thing that popped to mind.)
Bookmarks