Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 07-20-2009, 01:57 PM
Aland2929 Aland2929 is offline
Registered User
 
Join Date: 11 Jun 2009
Location: Cape Town
MS Office Version:Excel 2003
Posts: 43
Aland2929 is becoming part of the community
Create a chart

Please Register to Remove these Ads

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 11:00 AM.
Reply With Quote
  #2  
Old 07-21-2009, 04:09 AM
Andy Pope's Avatar
Andy Pope Andy Pope is offline
Forum Guru
 
Join Date: 10 May 2004
Location: Essex, UK
MS Office Version:2003 & 2007 sp2
Posts: 7,223
Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding
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
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 Off
Refbacks are Off

Forum Jump