Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 16th, 2008, 04:15 AM
Registered User
Join Date: Jun 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default [VB2005]adding second y-axis to chart

I need to use VB 2005 studio to create chart in Excel.

I actually record the Excel macro while inserting chart and all.
And now I have the VBA code.
However, I tried inserting into my VB 2005 and modify,
but I have some errors.

here's the VBA code:
================================================== ==
    ActiveChart.ChartType = xlLine
    ActiveChart.SetSourceData Source:=Sheets("Copy of 

trial").Range("A1:H23"), _
    ActiveChart.Location Where:=xlLocationAsNewSheet
    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "Animal Rack Monitor"
        .Axes(xlCategory, xlPrimary).HasTitle = True
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = 

        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = 

    End With
    With ActiveChart.Axes(xlCategory)
        .HasMajorGridlines = True
        .HasMinorGridlines = True
    End With
    With ActiveChart.Axes(xlValue)
        .HasMajorGridlines = True
        .HasMinorGridlines = True
    End With
    ActiveChart.HasLegend = True
    Selection.Position = xlRight
    With Selection.Border
        .ColorIndex = 57
        .Weight = xlMedium
        .LineStyle = xlContinuous
    End With
    With Selection
        .MarkerBackgroundColorIndex = xlNone
        .MarkerForegroundColorIndex = xlNone
        .MarkerStyle = xlNone
        .Smooth = False
        .MarkerSize = 3
        .Shadow = False
    End With
    ActiveChart.SeriesCollection(1).AxisGroup = 2
End Sub
================================================== ==
and the code i did in VB 2005 which is working ok:


        Dim objExcelC As Excel.Chart

        objExcelC = WBook.ActiveChart

        objExcelC.ChartType = Excel.XlChartType _

        objExcelC.Name = "ARM Chart"
        objExcelC.HasTitle = True
        'objExcelC.ChartTitle.Text = _
"Animal Rack Monitor"

    End Sub
End Class

================================================== ======
So can anyone guide me?

Some errors occurs when I attempt to convert are like xlLines, xlColumns are not declared....etc.


Reply With Quote
  #2 (permalink)  
Old June 16th, 2008, 11:45 AM
Friend of Wrox
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts

It would be helpful if you would edit your original post, and put a line continuation character on the really long lines, and shorten them. The browser makes a text area as wide as the widest line. Because of that, to read your question one needs to scroll horizontally... Difficult.

For instance:
    Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, _
                                       ByVal e As System.ComponentModel.CancelEventArgs) _
                                       Handles OpenFileDialog1.FileOk
                                       Now. You say, “Some errors [which occur] when I attempt to convert are like xlLines, xlColumns are not declared....etc.” It would be helpful if you could say what those “errors” were specifically (not the error [u]number</u>, but the message itself), and specify which line those errors are raised on.
Reply With Quote
  #3 (permalink)  
Old June 17th, 2008, 01:16 AM
Registered User
Join Date: Jun 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

hi..sorry abt that.

Already edited. :)

So far, I edited again and wrote the code and the graph work. But I got problem with this line of code to convert to VB.

I need some guidance in adding second y-axis into the chart.

here's the VBA code where I select one data to display as second y-axis ( I recorded the Excel Macro):

    ActiveChart.SeriesCollection(1).AxisGroup = 2

The graph and all run to what I want.

But now, I want only one series of data to be plot themselves in second y-axis instead of me selecting it.
the ideal graph I manually plot in in the attachment.

Any guidance? Thanks!
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Coloring the chart plot area based on x-axis scale simranjeev Reporting Services 1 October 25th, 2007 02:50 PM
Chart Axis label Colour dmunro Reporting Services 1 September 28th, 2006 03:30 PM
Problem in formating Y axis of Chart mayuri Crystal Reports 0 December 26th, 2005 08:15 AM
Using Customized chart for Pivot Chart kliu9 Excel VBA 3 October 13th, 2004 09:37 AM
Adding a second value axis to chart..? rstober Excel VBA 0 October 1st, 2003 02:47 PM

All times are GMT -4. The time now is 10:09 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.