Stretch8027
New Member
- Joined
- Nov 30, 2020
- Messages
- 4
- Office Version
- 2016
- Platform
- Windows
I have a chart embedded in a worksheet plotting 2 parameters. I need to do 2 things.
1. I want to use VBA to dynamically scale the axes whenever the data table updates.
The input table is in sheet1
The chart is in sheet 2
Code similar to that below would perform the function required, but i'm unsure how to define the chart object as it is inserted as an embedded object in a different worksheet. There is only one chart in the workbook. Not sure is i have to define variables or not
Sub ScaleAxes()
With ActiveChart.Axes(xlCategory, xlPrimary)
.MinimumScale = Sheet1.Range("P8").Value
.MaximumScale = Sheet1.Range("P9").Value
.MajorUnit = Sheet1.Range("P10").Value
End With
With ActiveChart.Axes(xlValue, xlPrimary)
.MinimumScale = Sheet1.Range("q8").Value
.MaximumScale = Sheet1.Range("q9").Value
.MajorUnit = Sheet1.Range("q10").Value
End With
End Sub
2. Insert code to re-run Macro after changing any values in the range C7:C17 on Sheet1 ("Input")
I hope I have managed to do a reasonable job of explaining my problem - VBA newbie
Thanks in advance
1. I want to use VBA to dynamically scale the axes whenever the data table updates.
The input table is in sheet1
The chart is in sheet 2
Code similar to that below would perform the function required, but i'm unsure how to define the chart object as it is inserted as an embedded object in a different worksheet. There is only one chart in the workbook. Not sure is i have to define variables or not
Sub ScaleAxes()
With ActiveChart.Axes(xlCategory, xlPrimary)
.MinimumScale = Sheet1.Range("P8").Value
.MaximumScale = Sheet1.Range("P9").Value
.MajorUnit = Sheet1.Range("P10").Value
End With
With ActiveChart.Axes(xlValue, xlPrimary)
.MinimumScale = Sheet1.Range("q8").Value
.MaximumScale = Sheet1.Range("q9").Value
.MajorUnit = Sheet1.Range("q10").Value
End With
End Sub
2. Insert code to re-run Macro after changing any values in the range C7:C17 on Sheet1 ("Input")
I hope I have managed to do a reasonable job of explaining my problem - VBA newbie
Thanks in advance