I am using the following code to dynamically size a graphs plot area to the same size as the data table below it but I am having problems with the plot area shifting when the table data is refreshed using a routine
Each time the data is refreshed the objPlot.Left is reducing by 1.
I have tried adding
after
but this doesn't seem to work.
Code:
Sub CoverRangeWithAChart()
Dim rngChart As Range
Dim rngPlot As Range
Dim objChart As ChartObject
Dim objPlot As PlotArea
Dim intTop As Integer
Dim intHeight As Integer
Dim intLeft As Integer
Dim intMax As Integer
Dim intCvDChartColRange As Integer
Dim rngCvDMaxRange As Range
Range("E31").Select
Do Until Selection.Offset(-2, intCvDChartColRange) = 0
intCvDChartColRange = intCvDChartColRange + 4
Loop
Set rngCvDMaxRange = Range(Selection, Selection.Offset(3, intCvDChartColRange))
intMax = WorksheetFunction.Max(rngCvDMaxRange) + 1
Set objChart = ActiveSheet.ChartObjects("Chart 1")
Set objPlot = objChart.Chart.PlotArea
With objChart
.Activate
.Select
End With
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = 0
.MaximumScale = intMax
.MinorUnitIsAuto = True
.MajorUnit = 1
End With
Set rngChart = ActiveSheet.Range(Range("A9"), Range("A9").Offset(18, Range("GraphColCount") + 4))
objChart.Height = rngChart.Height
objChart.Width = rngChart.Width
objChart.Top = rngChart.Top
objChart.Left = rngChart.Left
intTop = objPlot.Top
intHeight = objPlot.Height
intLeft = objPlot.Left
objPlot.Width = objPlot.Left + ((Range("GraphColCount") + 1) * 23.25)
objPlot.Left = intLeft
objPlot.Top = intTop
objPlot.Height = intHeight
End Sub
I have tried adding
Code:
objPlot.Left = objPlot.Left +1
Code:
objPlot.Left = intLeft