Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
tubbinator
 
Posts: n/a
Default Secondary axis with VBA


I'm using the following VBA code and I never see the secondary value
axis. Can anyone figure out why???

Excel 2003, VBA

Thanks,
Tubbs


Code:
--------------------
' create the chart
ActiveSheet.ChartObjects.Add Left:=50, Top:=50, Width:=750, Height:=300

With ActiveSheet.ChartObjects(1).Chart

' create first series, Magnitude
.SeriesCollection.NewSeries

With .SeriesCollection(1)
.Name = ActiveSheet.Range("D1").Value
.Values = ActiveSheet.Range("D2:D" + Format(linecount, "#"))
.XValues = ActiveSheet.Range("A2:A" + Format(linecount, "#"))
.AxisGroup = xlPrimary
End With

' create second series, Sync
.SeriesCollection.NewSeries

With .SeriesCollection(2)
.Name = ActiveSheet.Range("H1").Value
.Values = ActiveSheet.Range("H2:H" + Format(linecount, "#"))
.XValues = ActiveSheet.Range("A2:A" + Format(linecount, "#"))
.AxisGroup = xlPrimary
End With

' create third series, Phase
.SeriesCollection.NewSeries

With .SeriesCollection(3)
.Name = ActiveSheet.Range("E1").Value
.Values = ActiveSheet.Range("E2:E" + Format(linecount, "#"))
.XValues = ActiveSheet.Range("A2:A" + Format(linecount, "#"))
.AxisGroup = xlSecondary
End With



For Each ax In .Axes
'If Not ((ax.Type = xlCategory) And (ax.AxisGroup = xlSecondary)) Then
ax.HasTitle = True
With ax.AxisTitle
.Font.Name = "Arial"
.Font.Size = 10.75
.Font.Bold = True
End With
'End If
Next ax

With .Axes(xlValue, xlSecondary).AxisTitle
.Caption = "Phase (Degrees)"
.Orientation = 90
End With

With .Axes(xlValue, xlPrimary).AxisTitle
.Caption = "Magnitude (mV)"
.Orientation = 90
End With

With .Axes(xlCategory, xlPrimary).AxisTitle

.Caption = "Sample Number"

End With
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlCategory, xlSecondary) = False
.HasAxis(xlValue, xlPrimary) = True
.HasAxis(xlValue, xlSecondary) = True
.ChartType = xlLine

End With 'chart
--------------------


--
tubbinator
------------------------------------------------------------------------
tubbinator's Profile: http://www.excelforum.com/member.php...o&userid=28239
View this thread: http://www.excelforum.com/showthread...hreadid=477924

  #2   Report Post  
Jon Peltier
 
Posts: n/a
Default Secondary axis with VBA

Didn't you step through the code? Your chart had a secondary axis until the end when
you ran this line:

.ChartType = xlLine

The xlLine chart type by default has only primary axes, so running this line
obliterated the axis you worked so hard to construct. Move the line to the top,
right after this:

With ActiveSheet.ChartObjects(1).Chart

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

tubbinator wrote:

I'm using the following VBA code and I never see the secondary value
axis. Can anyone figure out why???

Excel 2003, VBA

Thanks,
Tubbs


Code:


  #3   Report Post  
Jon Peltier
 
Posts: n/a
Default Secondary axis with VBA

You replied to the wrong thread.

Sometimes putting .ChartType up too high will cause an error. If you specify a
bubble of stock chart type before specifying enough data to populate that chart
type, it will crash.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

tubbinator wrote:

Got a reply off of the Excel-L mailing list. Had to move the
".ChartType = xlLine" line up higher. Moved it to right after chart
creation. I could have sworn I'd gotten errors with that line up
higher before. Oh well.

Tubbs


Jon Peltier wrote:

Didn't you step through the code? Your chart had a secondary axis until
the end when you ran this line:

.ChartType = xlLine

The xlLine chart type by default has only primary axes, so running this
line obliterated the axis you worked so hard to construct. Move the line
to the top, right after this:

With ActiveSheet.ChartObjects(1).Chart

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

tubbinator wrote:

I'm using the following VBA code and I never see the secondary value
axis. Can anyone figure out why???

Excel 2003, VBA

Thanks,
Tubbs


Code:



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
Secondary Axis Ann Charts and Charting in Excel 5 October 21st 05 09:38 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
Stacked Bar Chart with Secondary Axis Benjamin B Charts and Charting in Excel 7 May 15th 05 04:00 AM
How do I set permanent secondary axis in PivotTable chart? Microlong Charts and Charting in Excel 3 January 8th 05 03:54 AM


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

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

About Us

"It's about Microsoft Excel"