The code you have re-used is a simple demonstration program which allows the axes of a chart to be manipulated when one of 6 specific cells on the worksheet is changed. However, these changes are intended to be made by the user through the keyboard. Making a change in this way triggers the Worksheet_Change
event and allows the changed cell to be identified. The code within the event routine modifies the chart's axes according to which specific worksheet cell has been changed.
Your issue, as David Ziemens noted in his comment, is that if a cell changes value because it is recalculated through a formula then this change does not trigger a Worksheet_Change
event. (Of course, it is entirely possible that a manually entered change elsewhere on the worksheet will have triggered both a Worksheet_Change
event and a recalculation causing a cell of interest to change its value via a formula. In this case, however, the Target
argument will identify the cell that was manually changed rather than the one recalculated through a formula.)
Throw away the Select ... Case
structure, that is really only useful in the context of the demonstration program you are trying to re-use. Instead, change the code so that it unconditionally updates all 4 of your chart properties directly from cells G161
and F163
(so use ws.Range("G161").Value
and ws.Range("F163").Value
instead of Target.Value
for assigning the chart properties, where ws
represents whichever worksheet these cells are located on - eg ActiveSheet
or Worksheets("Sheet1")
or whatever the worksheet is called). Wrap the assignment of the chart properties inside a Workbook_SheetChange
sub rather than Worksheet_Change
and your chart will update whenever the workbook recalculates.
This is not a very pure solution in that it does not detect whether cells F163
and G161
actually change when recalculation takes place. So it runs the risk that the 4 properties are being unnecessarily assigned with values that are unchanged. However, unless you have a very large workbook and you are pushing the limits of what your computer can handle, this won't matter from a practical point of view.