Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 3
Default secondary axis - setting -VBA

I hope this is the right user group...

I have a sheet of data for a nuber of projects. I then want to;
create a new sheet for each project and generate a chart on the new sheet.
This is all done with VBA.
It works except that I want to use the secondary axis however the code below
crashes excel when it tries to set the axisgroup.

Can anyone tell me where I am going wrong?

Thanks
Graham


Private Sub GeneratePlots()

Dim i, j
Dim shtPlot As Worksheet
Dim s As Worksheet
Dim rx As Range
Dim ry1 As Range
Dim ry2 As Range
Dim ry3 As Range
Dim ra() As Range
Dim oChart As ChartObject
Dim ChtTop As Long, ChtLeft As Long
Dim ChtHeight As Long, ChtWidth As Long


ChtTop = 20
ChtLeft = 20
ChtWidth = 400
ChtHeight = 400

For i = 1 To 2 ' UBound(mArrUIP, 1)

'add new sheet
mcXL.AddAsLastWorksheet CStr(mArrUIP(i, 1))
Set shtPlot = Worksheets(CStr(mArrUIP(i, 1)))

'add new chart to the new (active) sheet
Set oChart = Worksheets(CStr(mArrUIP(i, 1))).ChartObjects.Add(ChtLeft,
ChtTop, ChtWidth, ChtHeight)
oChart.name = CStr(mArrUIP(i, 1)) & "_1"
oChart.Chart.ChartType = xlLine

'add series
ReDim ra(3)
Set rx = mDataSheet.Range(mDataSheet.Cells(mArrUIP(i, 2), "C"),
mDataSheet.Cells(mArrUIP(i, 3), "C"))
Set ra(1) = mDataSheet.Range(mDataSheet.Cells(mArrUIP(i, 2), "G"),
mDataSheet.Cells(mArrUIP(i, 3), "G"))
Set ra(2) = mDataSheet.Range(mDataSheet.Cells(mArrUIP(i, 2), "K"),
mDataSheet.Cells(mArrUIP(i, 3), "K"))
Set ra(3) = mDataSheet.Range(mDataSheet.Cells(mArrUIP(i, 2), "T"),
mDataSheet.Cells(mArrUIP(i, 3), "T"))

For j = 1 To 3
With oChart.Chart

.SeriesCollection.NewSeries
.SeriesCollection(j).XValues = rx
.SeriesCollection(j).Values = ra(j)

.SeriesCollection(j).MarkerStyle = xlMarkerStyleNone
'.SeriesCollection(j).AxisGroup = xlSecondary <= CRASHES EXCEL

End With
Next

Next i


End Sub



  #2   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 2,489
Default secondary axis - setting -VBA

Hi,

It looks like you you are trying to put ALL of the data series on the
secondary axis.
There must be at least 1 series on the primary.

Cheers
Andy

--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
"graham_s" wrote in message
...
I hope this is the right user group...

I have a sheet of data for a nuber of projects. I then want to;
create a new sheet for each project and generate a chart on the new sheet.
This is all done with VBA.
It works except that I want to use the secondary axis however the code
below
crashes excel when it tries to set the axisgroup.

Can anyone tell me where I am going wrong?

Thanks
Graham


Private Sub GeneratePlots()

Dim i, j
Dim shtPlot As Worksheet
Dim s As Worksheet
Dim rx As Range
Dim ry1 As Range
Dim ry2 As Range
Dim ry3 As Range
Dim ra() As Range
Dim oChart As ChartObject
Dim ChtTop As Long, ChtLeft As Long
Dim ChtHeight As Long, ChtWidth As Long


ChtTop = 20
ChtLeft = 20
ChtWidth = 400
ChtHeight = 400

For i = 1 To 2 ' UBound(mArrUIP, 1)

'add new sheet
mcXL.AddAsLastWorksheet CStr(mArrUIP(i, 1))
Set shtPlot = Worksheets(CStr(mArrUIP(i, 1)))

'add new chart to the new (active) sheet
Set oChart = Worksheets(CStr(mArrUIP(i, 1))).ChartObjects.Add(ChtLeft,
ChtTop, ChtWidth, ChtHeight)
oChart.name = CStr(mArrUIP(i, 1)) & "_1"
oChart.Chart.ChartType = xlLine

'add series
ReDim ra(3)
Set rx = mDataSheet.Range(mDataSheet.Cells(mArrUIP(i, 2), "C"),
mDataSheet.Cells(mArrUIP(i, 3), "C"))
Set ra(1) = mDataSheet.Range(mDataSheet.Cells(mArrUIP(i, 2), "G"),
mDataSheet.Cells(mArrUIP(i, 3), "G"))
Set ra(2) = mDataSheet.Range(mDataSheet.Cells(mArrUIP(i, 2), "K"),
mDataSheet.Cells(mArrUIP(i, 3), "K"))
Set ra(3) = mDataSheet.Range(mDataSheet.Cells(mArrUIP(i, 2), "T"),
mDataSheet.Cells(mArrUIP(i, 3), "T"))

For j = 1 To 3
With oChart.Chart

.SeriesCollection.NewSeries
.SeriesCollection(j).XValues = rx
.SeriesCollection(j).Values = ra(j)

.SeriesCollection(j).MarkerStyle = xlMarkerStyleNone
'.SeriesCollection(j).AxisGroup = xlSecondary <= CRASHES EXCEL

End With
Next

Next i


End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to place a secondary y axis bar in a bar chart next to two primary y axis bars? Dmitry Excel Discussion (Misc queries) 3 May 4th 06 01:58 AM
How to place a secondary y axis bar in a bar chart next to two primary y axis bars? Dmitry Charts and Charting in Excel 2 May 4th 06 01:58 AM
Secondary Axis Match Primary Axis Gridlines [email protected] Charts and Charting in Excel 1 July 31st 05 09:23 PM
Pivot Table, Line Chart with Secondary Y axis, Page Field selection destroys Y2 axis [email protected] Charts and Charting in Excel 0 July 13th 05 09:30 PM
Secondary Axis Annual Units sold on 1 Y Axis - Dollar Volume on another John Smith Charts and Charting in Excel 7 December 21st 04 08:26 PM


All times are GMT +1. The time now is 06:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"