Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
D
 
Posts: n/a
Default Setting source data range with Charts

I'm trying to figure out how to define the source data range when the range
is not predetermined, when adding a chart in VBA. I can't just do "A1:B3",
because it will be an unknown number of rows (though always two columns). If
cells worked (as I've tried below), I could just use a variable for the
appropriate row reference, but no go so far. Any ideas? Thanks a lot.

With Charts(1)
.Location whe=xlLocationAsNewSheet
.SetSourceData Source:=Sheets("Sheet1").Range(Cells(1, 1),
Cells(2, 2)), PlotBy:=xlColumns
.ChartType = xlBarClustered
End With
  #3   Report Post  
Posted to microsoft.public.excel.charting
jeffP
 
Posts: n/a
Default Setting source data range with Charts

William: exactly the help I was also looking for. Thanks and Happy New Year
jeff

"William" wrote:

Hi

Sub ChartRange()
Dim r As Range, c As Chart
With Sheets("Sheet1")
Set r = .Range(.Range("A1"), _
..Range("A" & Rows.Count).End(xlUp).Offset(0, 1))
End With
Set c = Charts.Add
c.Location Whe=xlLocationAsNewSheet, Name:="MyChart"
c.SetSourceData Source:=r, PlotBy:=xlColumns
End Sub


--
XL2002
Regards

William



"D" wrote in message
...
| I'm trying to figure out how to define the source data range when the
range
| is not predetermined, when adding a chart in VBA. I can't just do
"A1:B3",
| because it will be an unknown number of rows (though always two columns).
If
| cells worked (as I've tried below), I could just use a variable for the
| appropriate row reference, but no go so far. Any ideas? Thanks a lot.
|
| With Charts(1)
| .Location whe=xlLocationAsNewSheet
| .SetSourceData Source:=Sheets("Sheet1").Range(Cells(1, 1),
| Cells(2, 2)), PlotBy:=xlColumns
| .ChartType = xlBarClustered
| End With



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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Individual labels to data point in Excel charts Sverre Rolseth Charts and Charting in Excel 2 December 8th 04 12:55 PM
Excel 97 chart opened in Excel 2003 - Source Data problem DHunt Charts and Charting in Excel 0 December 6th 04 08:05 PM
Problem with graph ranges No Such Luck Charts and Charting in Excel 6 December 3rd 04 01:09 PM
Formulas in source data Ken Charts and Charting in Excel 3 December 1st 04 05:43 PM
Named dynamic ranges, copied worksheets and graph source data WP Charts and Charting in Excel 1 November 28th 04 05:19 PM


All times are GMT +1. The time now is 07:14 PM.

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"