+ Reply to Thread
Results 1 to 2 of 2

Thread: Create a chart

  1. #1
    Valued Forum Contributor
    Join Date
    06-11-2009
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    265

    Create a chart

    Hi All,
    My chart was working until I introduced two options buttons to determine the data to plot (units or value). When I run the code a chart is not displayed?
    Please help.
    Thank You.

    Code:
    Sub CreateChart()
    Dim unitsORrands As Integer
    
    '   Choose data to plot
        If Range("unitsORrands") = 1 Then
    
    ' Create chart with UNIT data
            Range("UnitChartData").Select
            Range("C337").Activate
            ActiveSheet.Shapes.AddChart.Select
            ActiveChart.SetSourceData Source:=Range("UnitChartData")
            ActiveChart.ChartType = xlLine
            ActiveChart.ClearToMatchStyle
            ActiveChart.ChartStyle = 42
            ActiveChart.ClearToMatchStyle
            ActiveChart.SetElement (msoElementChartTitleAboveChart)
            ActiveChart.ChartTitle.Text = "=BranchName"
        Range("BranchChosen").Select
        End If
        Exit Sub
        
        If Range("unitsORrands") = 2 Then
        
        ' Create chart with RAND data
            Range("RandChartData").Select
            Range("C337").Activate
            ActiveSheet.Shapes.AddChart.Select
            ActiveChart.SetSourceData Source:=Range("RandChartData")
            ActiveChart.ChartType = xlLine
            ActiveChart.ClearToMatchStyle
            ActiveChart.ChartStyle = 42
            ActiveChart.ClearToMatchStyle
            ActiveChart.SetElement (msoElementChartTitleAboveChart)
            ActiveChart.ChartTitle.Text = "=BranchName"
        Range("BranchChosen").Select
        End If
        
        
    End Sub
    Last edited by Aland2929; 07-23-2009 at 12:00 PM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,924

    Re: Create a chart

    What does the Range("unitsORrands") contain?

    If it's 1 then it should do the first part of your code.
    If not then it will do nothing as you have a Exit Sub in the middle of your code.
    Cheers
    Andy
    www.andypope.info

Thread Information

Users Browsing this Thread

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

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.2.0