J
jonwatts
I am trying to use VBA to dynamically produce a number of charts. Th
number of charts produced depends on the amount of data that appears i
a seperate spreadsheet...
I have taken the code produced when I recorded a macro to produce on
such chart and adapted it to meet my needs, however I am getting erro
1004, "Unable to set the XValues property of the Series class" when
try to assign the x-axis values using a range I have dynamicall
created.
I'm sure the problem is somewhere with my syntax, but however I try t
phrase it I cannot seem to get it to work.
Please find a copy of my code below - any help would be muc
appreciated!
Jon
In the following code the variable Count determines how many chart
will need to be produced:
<code>
Dim i As Integer
Dim Count As Integer
Dim intGraphDisplayStartRow As Integer
Dim rngTempRange1 As Range
Dim rngTempRange2 As Range
Dim rngTempRange3 As Range
If Count > 0 Then
For i = 1 To Count
intGraphDisplayStartRow = (i * 13) + 2
ThisWorkbook.Worksheets("Page 2").Select
Charts.Add
Set rngTempRange1
ThisWorkbook.Worksheets("WorkspaceTemp") _
.Range("A" & Trim(CStr(intGraphDisplayStartRow _
& ":A" & intGraphDisplayStartRow + 11)))
Set rngTempRange2
ThisWorkbook.Worksheets("WorkspaceTemp") _
.Range("C" & Trim(CStr(intGraphDisplayStartRow)) & ":C
_
& Trim(CStr(intGraphDisplayStartRow + 11)))
Set rngTempRange3
ThisWorkbook.Worksheets("WorkspaceTemp") _
.Range("C" & Trim(CStr(intGraphDisplayStartRow - 1)))
ActiveChart.ChartType = xlLine
ActiveChart.SeriesCollection(1).XValues = rngTempRange1
ActiveChart.SeriesCollection(1).Values = rngTempRange2
ActiveChart.SeriesCollection(1).Name = rngTempRange3
ActiveChart.Location Where:=xlLocationAsObject, Name:="Pag
2"
Next
End If
</code
number of charts produced depends on the amount of data that appears i
a seperate spreadsheet...
I have taken the code produced when I recorded a macro to produce on
such chart and adapted it to meet my needs, however I am getting erro
1004, "Unable to set the XValues property of the Series class" when
try to assign the x-axis values using a range I have dynamicall
created.
I'm sure the problem is somewhere with my syntax, but however I try t
phrase it I cannot seem to get it to work.
Please find a copy of my code below - any help would be muc
appreciated!
Jon
In the following code the variable Count determines how many chart
will need to be produced:
<code>
Dim i As Integer
Dim Count As Integer
Dim intGraphDisplayStartRow As Integer
Dim rngTempRange1 As Range
Dim rngTempRange2 As Range
Dim rngTempRange3 As Range
If Count > 0 Then
For i = 1 To Count
intGraphDisplayStartRow = (i * 13) + 2
ThisWorkbook.Worksheets("Page 2").Select
Charts.Add
Set rngTempRange1
ThisWorkbook.Worksheets("WorkspaceTemp") _
.Range("A" & Trim(CStr(intGraphDisplayStartRow _
& ":A" & intGraphDisplayStartRow + 11)))
Set rngTempRange2
ThisWorkbook.Worksheets("WorkspaceTemp") _
.Range("C" & Trim(CStr(intGraphDisplayStartRow)) & ":C
_
& Trim(CStr(intGraphDisplayStartRow + 11)))
Set rngTempRange3
ThisWorkbook.Worksheets("WorkspaceTemp") _
.Range("C" & Trim(CStr(intGraphDisplayStartRow - 1)))
ActiveChart.ChartType = xlLine
ActiveChart.SeriesCollection(1).XValues = rngTempRange1
ActiveChart.SeriesCollection(1).Values = rngTempRange2
ActiveChart.SeriesCollection(1).Name = rngTempRange3
ActiveChart.Location Where:=xlLocationAsObject, Name:="Pag
2"
Next
End If
</code