Note that there are some explanatory texts on larger screens.

plurals
  1. POLinking ChChart control to Spreadsheet control data
    primarykey
    data
    text
    <p>I want to be able to embed a chart control in a VBA form, allowing the user to click on parts of the control, which will populate a hidden spreadsheet with data with the X &amp; Y values clicked.</p> <p>I got as far as adding the "Microsoft Office Chat 11.0" and "Microsoft Office Spreadsheet 11.0" controls using the Additional Controls mechanism and placing one of each on the form. However, for the life of me I can't seem to bind the chart to the data contained in the spreadsheet. One option I considered was</p> <pre><code>Dim SpdShtCtr As Spreadsheet Dim ChartControl As ChChart Dim XValues() As Variant, YValues() As Variant XValues = WorksheetFunction.Transpose(SpdShtCtrl.Range("XValues")) YValues = WorksheetFunction.Transpose(SpdShtCtrl.Range("YValues")) Dim c Set c = ChartControl.Constants With ChartControl .Clear .Charts.Add With .Charts(0).SeriesCollection.Add .Caption = "Data" .SetData c.vbDimCategories, c.chDataLiteral, XValues .SetData c.vbDimValues, c.chDataLiteral, YValues End With End With </code></pre> <p>The problem with this is that it is not dynamic - if the data in the spreadsheet changes, the chart will not automatically update. Also, this does not work. I get the error "Object does not support this property or method" on <code>.SetData ...</code></p> <p>The other option was something like this</p> <pre><code>Dim SpdShtCtr As Spreadsheet Dim ChartControl As ChChart Dim XValues As Range, YValues As Range Set XValues = SpdShtCtrl.Range("XValues") Set YValues = SpdShtCtrl.Range("YValues") Dim c Set c = ChartControl.Constants With ChartControl .DataSource = SpdShtCtrl .Clear .Charts.Add With .Charts(0).SeriesCollection.Add .Caption = "Data" .SetData c.vbDimCategories, c.chWORKSHEETRANGECONSTANT, XValues .SetData c.vbDimValues, c.chWORKSHEETRANGECONSTANT, YValues End With End With </code></pre> <p>But I don't know if this is the correct way to bind these controls together, and even if it is, what the constant definitions should be, in place of <code>WORKSHEETRANGECONSTANT</code>, to define linking to a worksheet range.</p> <p>Can anyone point me in the right direction?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload