#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBA Help

Hi all,

I'm trying to programatically change the source data of a chart using the
following code:

Dim Workbook As Workbook, Chart As Chart

Set Workbook = Excel.Application.ActiveWorkbook

Workbook.Sheets("NISTData").Activate

Workbook.ActiveSheet.Range("A1").Select

Workbook.ActiveSheet.Range(Selection, Selection.End(xlDown)).Select

Set Chart = Workbook.Charts("NIST1976")

Chart.SetSourceData Workbook.ActiveSheet.Range(Selection,
Selection.Offset(0, 1)).Select

When I run this, I get a "Object Required" error on the last line
(essentially this is setting the source data of the chart to both the
columns in the "NIST1976" sheet)

What obvious thing have I missed?

thanks and kind regards

CK


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBA Help

Greg - it works great - many thanks!


Greg Wilson wrote:
Try:

Sub ChangeSourceData()
Dim SorRng As Range, Rw As Long
With Sheets("NISTData")
Rw = .Range("A1").End(xlDown).Row
Set SorRng = .Range("A1:B" & Rw)
End With
Charts("NIST1976").SetSourceData SorRng
End Sub

Regards,
Greg


-----Original Message-----
Hi all,

I'm trying to programatically change the source data of a chart
using the following code:

Dim Workbook As Workbook, Chart As Chart

Set Workbook = Excel.Application.ActiveWorkbook

Workbook.Sheets("NISTData").Activate

Workbook.ActiveSheet.Range("A1").Select

Workbook.ActiveSheet.Range(Selection, Selection.End (xlDown)).Select

Set Chart = Workbook.Charts("NIST1976")

Chart.SetSourceData Workbook.ActiveSheet.Range(Selection,
Selection.Offset(0, 1)).Select

When I run this, I get a "Object Required" error on the last line
(essentially this is setting the source data of the chart to both the
columns in the "NIST1976" sheet)

What obvious thing have I missed?

thanks and kind regards

CK


.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA Help

you don't have to use vBA to dynamically change source
data for graphs, can be done using named ranges. Found a
very helpful article (from California company I think).
Try a net search.
-----Original Message-----
Greg - it works great - many thanks!


Greg Wilson wrote:
Try:

Sub ChangeSourceData()
Dim SorRng As Range, Rw As Long
With Sheets("NISTData")
Rw = .Range("A1").End(xlDown).Row
Set SorRng = .Range("A1:B" & Rw)
End With
Charts("NIST1976").SetSourceData SorRng
End Sub

Regards,
Greg


-----Original Message-----
Hi all,

I'm trying to programatically change the source data

of a chart
using the following code:

Dim Workbook As Workbook, Chart As Chart

Set Workbook = Excel.Application.ActiveWorkbook

Workbook.Sheets("NISTData").Activate

Workbook.ActiveSheet.Range("A1").Select

Workbook.ActiveSheet.Range(Selection, Selection.End

(xlDown)).Select

Set Chart = Workbook.Charts("NIST1976")

Chart.SetSourceData Workbook.ActiveSheet.Range

(Selection,
Selection.Offset(0, 1)).Select

When I run this, I get a "Object Required" error on

the last line
(essentially this is setting the source data of the

chart to both the
columns in the "NIST1976" sheet)

What obvious thing have I missed?

thanks and kind regards

CK


.




.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"