+ Reply to Thread
Results 1 to 4 of 4

Problem in creating chart using VBA macro

Hybrid View

  1. #1
    Registered User
    Join Date
    11-27-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    2

    Exclamation Problem in creating chart using VBA macro

    Hi All,

    I have created chart using Excel VBA in the version 2010.
    The following is the code. This has been working fine in my system which has 2010.

    Sub create_chart_RCSAnalysis(frm_date As String, to_date As String)
        Dim lr, ur As Integer
           Dim WSD As Worksheet
           Set WSD = Worksheets("Actual-Output")     'Data source
    
           Dim CSD As Worksheet
           Set CSD = Worksheets("Actual-Reports")     'Chart Output
        lr = find_rowno(frm_date)
        ur = find_rowno(to_date)
        
        If lr = 0 Then
            MsgBox ("The Inputted From Date is not in the valid Date Range. Please check and try again.")
            Exit Sub
        ElseIf ur = 0 Then
            MsgBox ("The Inputted To Date is not in the valid Date Range. Please check and try again.")
            Exit Sub
        Else
            CSD.Select
            ActiveSheet.Shapes.AddChart.Select
            ActiveChart.ChartType = xlColumnClustered
            ActiveChart.Parent.Name = "Chart_RCS_Analysis"
            ActiveChart.SeriesCollection.NewSeries
            ActiveChart.SeriesCollection(1).Name = "=""Total TC's Introduced"""
            ActiveChart.SeriesCollection(1).Values = WSD.Range(WSD.Cells(lr, 24), WSD.Cells(ur, 24))
            ActiveChart.SeriesCollection.NewSeries
            ActiveChart.SeriesCollection(2).Name = "=""Total RCS Introduced"""
            ActiveChart.SeriesCollection(2).Values = WSD.Range(WSD.Cells(lr, 23), WSD.Cells(ur, 23))
            ActiveChart.SeriesCollection.NewSeries
            ActiveChart.SeriesCollection(3).Name = "=""No of Testers"""
            ActiveChart.SeriesCollection(3).Values = WSD.Range(WSD.Cells(lr, 30), WSD.Cells(ur, 30))
            ActiveChart.SeriesCollection.NewSeries
            ActiveChart.SeriesCollection(4).Name = "=""No of Days"""
            ActiveChart.SeriesCollection(4).Values = WSD.Range(WSD.Cells(lr, 31), WSD.Cells(ur, 31))
            ActiveChart.SeriesCollection(4).XValues = WSD.Range(WSD.Cells(lr, 2), WSD.Cells(ur, 2))
            ActiveChart.SeriesCollection(1).Select
            ActiveChart.SeriesCollection(1).ChartType = xlLine
            ActiveChart.SeriesCollection(1).Select
            ActiveChart.SeriesCollection(1).AxisGroup = 2
          End If
      End Sub
    But, when i tried running this in Excel 2003.
    I am hitting the "object doesn't support this property" error.
    The error is hitting in this line of code.-ActiveSheet.Shapes.AddChart.Select

    Please help me to understand whether this is the issue with the Excel versio.
    also, please help to get resolved of this issue.

    Moderator Note:

    Pls use code tags around your code next time as per forum rules.
    Last edited by Fotis1991; 11-27-2013 at 02:53 AM.

  2. #2
    Forum Contributor
    Join Date
    11-05-2013
    Location
    Germany
    MS-Off Ver
    Excel 2013
    Posts
    120

    Re: Problem in creating chart using VBA macro

    Hey,

    found the answer in another post.

    "There was no Shapes.AddChart method in 2003. Use CHarts.Add and then:"

    Activechart.Location xlLocationAsObject, "sheet name here"
    here is the link to the original post and all credit for the solution goes to romperstomper

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Problem in creating chart using VBA macro

    Another method for what it's worth.

            With ActiveSheet.ChartObjects.Add(Left:=100, Width:=375, Top:=75, Height:=225).Chart
                .Parent.Name = "Chart_RCS_Analysis"
                With .SeriesCollection.NewSeries    'Series 1
                    .ChartType = xlLine
                    .Name = "=""Total TC's Introduced"""
                    .Values = WSD.Range(WSD.Cells(lr, 24), WSD.Cells(ur, 24))
                End With
                With .SeriesCollection.NewSeries    'Series 2
                    .ChartType = xlColumnClustered
                    .Name = "=""Total RCS Introduced"""
                    .Values = WSD.Range(WSD.Cells(lr, 23), WSD.Cells(ur, 23))
                End With
                With .SeriesCollection.NewSeries    'Series 3
                    .ChartType = xlColumnClustered
                    .Name = "=""No of Testers"""
                    .Values = WSD.Range(WSD.Cells(lr, 30), WSD.Cells(ur, 30))
                End With
                With .SeriesCollection.NewSeries    'Series 4
                    .ChartType = xlColumnClustered
                    .Name = "=""No of Days"""
                    .Values = WSD.Range(WSD.Cells(lr, 31), WSD.Cells(ur, 31))
                    .XValues = WSD.Range(WSD.Cells(lr, 2), WSD.Cells(ur, 2))
                End With
                .SeriesCollection(1).AxisGroup = 2
            End With
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    11-27-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    2

    Thumbs up [Solved] Re: Problem in creating chart using VBA macro

    Thanks for the help, Alphafrog!!
    This is working for me well.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem creating a dynamic chart
    By kbaruin in forum Excel General
    Replies: 0
    Last Post: 09-20-2012, 08:55 AM
  2. Problem creating OHLC chart
    By jrp1982 in forum Excel General
    Replies: 4
    Last Post: 07-04-2012, 08:12 AM
  3. Excel 2007 : Problem creating Clustered Column Chart
    By Zotius in forum Excel General
    Replies: 0
    Last Post: 04-21-2010, 04:38 AM
  4. Problem creating chart?
    By sanjeev40084 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 06-15-2009, 12:07 PM
  5. Problem with empty cells when creating chart using vba
    By Xavier in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 04-17-2006, 05:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1