G
Greg Fish
After getting through, what I thought was the hard part, that is solving the
riddle of
Run-time error '1004': Unable to set the XValues property of the Series class
My next question is how do you go about programmatically formatting a chart.
I have recorded a macro, and taken code snippets from the macro, and
attempted to implement the code from the macro but inevitable it leads to
errrors. I have seen several examples of the following code
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
however, when I attempt to use the above it does not work
Sub graphIt(x1Axis As String, y1Axis As String, x_EST As String, y_EST As
String, curve As String)
Dim objWorkSheet As Object
Dim Y_data_range, X_data_range As Range
Dim Y_est_data_range, X_est_data_range As Range
Dim sY_data_range As String
Dim sX_data_range As String
Dim sY_est_data_range As String
Dim sX_est_data_range As String
Dim fittedCurve As String
Dim fuelCurve As ChartObject
Dim seriesData As Series
Dim seriesEst As Series
Worksheets(2).Activate
Set Y_data_range = ActiveSheet.Range(y1Axis)
Set X_data_range = ActiveSheet.Range(x1Axis)
Set Y_est_data_range = ActiveSheet.Range(y_EST)
Set X_est_data_range = ActiveSheet.Range(x_EST)
sY_data_range = "'" & ActiveSheet.Name & "'!" &
Y_data_range.Address(ReferenceStyle:=xlR1C1)
sX_data_range = "'" & ActiveSheet.Name & "'!" &
X_data_range.Address(ReferenceStyle:=xlR1C1)
sY_est_data_range = "'" & ActiveSheet.Name & "'!" &
Y_est_data_range.Address(ReferenceStyle:=xlR1C1)
sX_est_data_range = "'" & ActiveSheet.Name & "'!" &
X_est_data_range.Address(ReferenceStyle:=xlR1C1)
fittedCurve = curve
Worksheets(1).Activate
Set fuelCurve = ActiveSheet.ChartObjects.Add _
(Left:=150, Width:=750, Top:=25, Height:=450)
With fuelCurve.Chart
'make smoth XY Scatter Chart
.chartType = xlXYScatterSmooth
'.ChartTitle ' add string
Selection.Interior.ColorIndex = xlNone
'
' add series from selected name ranges
With .SeriesCollection.NewSeries
.Values = "=" & sY_data_range
.XValues = "=" & sX_data_range
.Name = "Data"
' .LineStyle = xlNone
' .Trendlines.Add(Type:=xlExponential)
End With
With .SeriesCollection.NewSeries
.Values = "=" & sY_est_data_range
.XValues = "=" & sX_est_data_range
.Name = "Estimated"
End With
End With
With Excel.ActiveWorkbook.ActiveChart.Axes(xlCategory) ERROR
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
With Excel.ActiveWorkbook.ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
End Sub
Results in a
Runtime Error '91'
Object varialble or With block varaible not set
riddle of
Run-time error '1004': Unable to set the XValues property of the Series class
My next question is how do you go about programmatically formatting a chart.
I have recorded a macro, and taken code snippets from the macro, and
attempted to implement the code from the macro but inevitable it leads to
errrors. I have seen several examples of the following code
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
however, when I attempt to use the above it does not work
Sub graphIt(x1Axis As String, y1Axis As String, x_EST As String, y_EST As
String, curve As String)
Dim objWorkSheet As Object
Dim Y_data_range, X_data_range As Range
Dim Y_est_data_range, X_est_data_range As Range
Dim sY_data_range As String
Dim sX_data_range As String
Dim sY_est_data_range As String
Dim sX_est_data_range As String
Dim fittedCurve As String
Dim fuelCurve As ChartObject
Dim seriesData As Series
Dim seriesEst As Series
Worksheets(2).Activate
Set Y_data_range = ActiveSheet.Range(y1Axis)
Set X_data_range = ActiveSheet.Range(x1Axis)
Set Y_est_data_range = ActiveSheet.Range(y_EST)
Set X_est_data_range = ActiveSheet.Range(x_EST)
sY_data_range = "'" & ActiveSheet.Name & "'!" &
Y_data_range.Address(ReferenceStyle:=xlR1C1)
sX_data_range = "'" & ActiveSheet.Name & "'!" &
X_data_range.Address(ReferenceStyle:=xlR1C1)
sY_est_data_range = "'" & ActiveSheet.Name & "'!" &
Y_est_data_range.Address(ReferenceStyle:=xlR1C1)
sX_est_data_range = "'" & ActiveSheet.Name & "'!" &
X_est_data_range.Address(ReferenceStyle:=xlR1C1)
fittedCurve = curve
Worksheets(1).Activate
Set fuelCurve = ActiveSheet.ChartObjects.Add _
(Left:=150, Width:=750, Top:=25, Height:=450)
With fuelCurve.Chart
'make smoth XY Scatter Chart
.chartType = xlXYScatterSmooth
'.ChartTitle ' add string
Selection.Interior.ColorIndex = xlNone
'
' add series from selected name ranges
With .SeriesCollection.NewSeries
.Values = "=" & sY_data_range
.XValues = "=" & sX_data_range
.Name = "Data"
' .LineStyle = xlNone
' .Trendlines.Add(Type:=xlExponential)
End With
With .SeriesCollection.NewSeries
.Values = "=" & sY_est_data_range
.XValues = "=" & sX_est_data_range
.Name = "Estimated"
End With
End With
With Excel.ActiveWorkbook.ActiveChart.Axes(xlCategory) ERROR
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
With Excel.ActiveWorkbook.ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
End Sub
Results in a
Runtime Error '91'
Object varialble or With block varaible not set