Thread: Chart code
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jon Peltier Jon Peltier is offline
external usenet poster
 
Posts: 6,582
Default Chart code

Check out the non-VBA checkbox example on this web page:

http://peltiertech.com/Excel/Charts/ChartByControl.html

A few coding suggestions:

Don't combine lines of code using a colon (:). It makes the code harder to
follow, especially in the "Else: blah blah" line in your code.

This line suffers from trying to assign the series values to a string:
ActiveChart.SeriesCollection(1).Values = "0"

You could set it to a literal representation of an array of one or more
zeros, e.g.:
ActiveChart.SeriesCollection(1).Values = "={0}"
ActiveChart.SeriesCollection(1).Values = "={0,0,0,0}"

Or you could point the values at an empty range of the appropriate size:
ActiveChart.SeriesCollection(1).Values = "=Sheet1!R1C26:R25C26"

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


"keri" wrote in message
ups.com...
Dim checkbox1 As Boolean
Worksheets("sheet3").ChartObjects(3).Activate
ActiveChart.SeriesCollection(1).XValues = "=Sheet3!R3C1:R27C1"
If checkbox1 = True Then
ActiveChart.SeriesCollection(1).Values = "=Sheet3!R3C2:R27C2"
Else: ActiveChart.SeriesCollection(1).Values = "0"
ActiveChart.SeriesCollection(1).Name = "=Sheet3!R2C2"
ActiveChart.SeriesCollection(2).Values = "=Sheet3!R3C3:R27C3"
ActiveChart.SeriesCollection(2).Name = "=Sheet3!R2C3"
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet3"
ActiveChart.HasDataTable = False
End If
End Sub

I have recorded most of the above code from a macro. The first line
(worksheets("sheet3") etc) generates an error and I haven't a clue what
the heck i am doing wrong now.

Second to this I have added in the If Else rows as I want a data series
only to appear if a checkbox is selected. Is this correct?