electricpete
Technical User
I want to create a chart that will have many user controls. I would like to have the chart embedded in a spreadsheet with many parameters accross the top of the sheet that control the chart's appearnce (for example xmin, xmax, ymin, ymax... many more to follow). When the user changes a cell, the worksheet change event sub will look at which cell was changed and decide what to do.
I have programmed this in excel file linked here:
The code is shown below.
The problem is: The sub doesn't seem to do anything until the second time I enter the cell. For example if I change xmax, nothing happens. If I select another cell and then select xmax, the chart updates. I also put msgbox("hello") into the code for changing xmin. It doesn't execute until the second time that cell is visited.
Why doesn't the code execute immediately when the data is changed ?
Thanks in advance for any suggestions.
I have programmed this in excel file linked here:
The code is shown below.
The problem is: The sub doesn't seem to do anything until the second time I enter the cell. For example if I change xmax, nothing happens. If I select another cell and then select xmax, the chart updates. I also put msgbox("hello") into the code for changing xmin. It doesn't execute until the second time that cell is visited.
Why doesn't the code execute immediately when the data is changed ?
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target(1, 1) = Range("xmin") Then
With ActiveSheet.ChartObjects(1).Chart.Axes(xlCategory)
.MinimumScale = Target
End With
MsgBox ("hello")
End If
If Target(1, 1) = Range("xmax") Then
With ActiveSheet.ChartObjects(1).Chart.Axes(xlCategory)
.MaximumScale = Target
End With
End If
If Target(1, 1) = Range("ymin") Then
With ActiveSheet.ChartObjects(1).Chart.Axes(xlValue)
.MinimumScale = Target
End With
End If
If Target(1, 1) = Range("ymax") Then
With ActiveSheet.ChartObjects(1).Chart.Axes(xlValue)
.MaximumScale = Target
End With
End If
' Stop
End Sub