error when setting XValues for chart

  • Thread starter Thread starter bodhi2.71828
  • Start date Start date
B

bodhi2.71828

Please help -- why do the last two lines cause Error 438 "Object
doesn't support this property or method"?

Dim rngXValues As Range, rngValues As Range
Set rngXValues = Range(Cells(12, 8).Cells, Cells(intLastRow, 8).Cells)
rngXValues.Select
Set rngValues = Range(Cells(12, intAskColumn).Cells, Cells(intLastRow,
intAskColumn).Cells)
rngValues.Select
Charts.Add
ActiveChart.Name = "MyChart"
ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=Sheets("Data").rngValues,
PlotBy:=xlRows
ActiveChart.SeriesCollection(1).XValues = Worksheets("Data").rngXValues

The rng.Select statements work fine, so I know the ranges exist and are
correct. So what is the proper way to set the SourceData and XValues
properties? Thanks.
 
Use the Worksheet object when you set the ranges...
Set rngValues = Worksheets("Data").Range(Cells(12, intAskColumn), _
Cells(intLastRow, intAskColumn))
Then use the range object as the location...
ActiveChart.SetSourceData Source:=rngValues, PlotBy:=xlRows

If you have more than one sheet to reference, it is best to always
qualify ranges with the correct sheet.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


<[email protected]>
wrote in message
Please help -- why do the last two lines cause Error 438 "Object
doesn't support this property or method"?

Dim rngXValues As Range, rngValues As Range
Set rngXValues = Range(Cells(12, 8).Cells, Cells(intLastRow, 8).Cells)
rngXValues.Select
Set rngValues = Range(Cells(12, intAskColumn).Cells, Cells(intLastRow,
intAskColumn).Cells)
rngValues.Select
Charts.Add
ActiveChart.Name = "MyChart"
ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=Sheets("Data").rngValues,
PlotBy:=xlRows
ActiveChart.SeriesCollection(1).XValues = Worksheets("Data").rngXValues

The rng.Select statements work fine, so I know the ranges exist and are
correct. So what is the proper way to set the SourceData and XValues
properties? Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

chart range to include variables - Macro 1
Loop to create charts 1
Excel Macro for Charts 1
Error Creating Chart 1
Excel Macro Help for Charts 8
Floating Chart? 1
FOR loop macro 5
Setting chart Xvalue errors 5

Back
Top