Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Discontiguous Chart Source

I want to create a chart with 1 serie which has data from 4 discontiguous
cells.
I defined 'b=6' but in practice it has a variable value, also counter has
variable values.
I tried two methods:
1/ with the union method to make a multirange selection
2/ by combining the cell addresses to a string.
None of these works. How do I solve this?

thanx in advance

Sub Macro1()
Charts.Add
With ActiveChart
.ChartType = xlColumnClustered
.SetSourceData Source:=Sheets("Summery").Range("A21:I40"), PlotBy:=xlRows
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = "={""x1"",""x2"",""x3"",""x4""}"

Set temprange = Range(Cells(2, b))
For counter = 4 To 8 Step 2
Set temprange = Union(temprange, Range(Cells(counter, b)))
Next
.SeriesCollection(1).Values = temprange

'tempstring = Cells(2, b).Address
'For counter = 4 To 8 Step 2
' tempstring = tempstring & "," & Cells(counter, b).Address
'Next
'.SeriesCollection(1).Values = range(tempstring)

.SeriesCollection(1).Name = "=""test"""
.Location Whe=xlLocationAsObject, Name:="Summery"
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Discontiguous Chart Source

The syntax for a chart series would be:

..SeriesCollection(1).XValues = Sheets(1).Range("B5, B8, B11, B35")

"Roland" wrote:

I want to create a chart with 1 serie which has data from 4 discontiguous
cells.
I defined 'b=6' but in practice it has a variable value, also counter has
variable values.
I tried two methods:
1/ with the union method to make a multirange selection
2/ by combining the cell addresses to a string.
None of these works. How do I solve this?

thanx in advance

Sub Macro1()
Charts.Add
With ActiveChart
.ChartType = xlColumnClustered
.SetSourceData Source:=Sheets("Summery").Range("A21:I40"), PlotBy:=xlRows
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = "={""x1"",""x2"",""x3"",""x4""}"

Set temprange = Range(Cells(2, b))
For counter = 4 To 8 Step 2
Set temprange = Union(temprange, Range(Cells(counter, b)))
Next
.SeriesCollection(1).Values = temprange

'tempstring = Cells(2, b).Address
'For counter = 4 To 8 Step 2
' tempstring = tempstring & "," & Cells(counter, b).Address
'Next
'.SeriesCollection(1).Values = range(tempstring)

.SeriesCollection(1).Name = "=""test"""
.Location Whe=xlLocationAsObject, Name:="Summery"
End With
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Discontiguous Chart Source

That doesn't work or a discontiguous range. You need to construct the string
which combines each area's worksheet-referenced address:

Sub ChartSeriesData()
Dim rngData As Range
Dim rArea As Range
Dim sAddress As String

Set rngData = ActiveSheet.Range("B5,B8,B11,B35")
sAddress = "="
For Each rArea In rngData.Areas
sAddress = sAddress & "'" & ActiveSheet.Name & "'!" & rArea.Address(, ,
xlR1C1) & ","
Next
sAddress = Left$(sAddress, Len(sAddress) - 1)
ActiveSheet.ChartObjects(1).Chart.SeriesCollection (1).XValues = sAddress

End Sub

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


"JLGWhiz" wrote in message
...
The syntax for a chart series would be:

.SeriesCollection(1).XValues = Sheets(1).Range("B5, B8, B11, B35")

"Roland" wrote:

I want to create a chart with 1 serie which has data from 4 discontiguous
cells.
I defined 'b=6' but in practice it has a variable value, also counter has
variable values.
I tried two methods:
1/ with the union method to make a multirange selection
2/ by combining the cell addresses to a string.
None of these works. How do I solve this?

thanx in advance

Sub Macro1()
Charts.Add
With ActiveChart
.ChartType = xlColumnClustered
.SetSourceData Source:=Sheets("Summery").Range("A21:I40"),
PlotBy:=xlRows
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = "={""x1"",""x2"",""x3"",""x4""}"

Set temprange = Range(Cells(2, b))
For counter = 4 To 8 Step 2
Set temprange = Union(temprange, Range(Cells(counter, b)))
Next
.SeriesCollection(1).Values = temprange

'tempstring = Cells(2, b).Address
'For counter = 4 To 8 Step 2
' tempstring = tempstring & "," & Cells(counter, b).Address
'Next
'.SeriesCollection(1).Values = range(tempstring)

.SeriesCollection(1).Name = "=""test"""
.Location Whe=xlLocationAsObject, Name:="Summery"
End With
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Discontiguous Chart Source

Now I remember why I do most of my charts manually and just use VBA to call
them up. Thanks for the lesson Jon.

"Jon Peltier" wrote:

That doesn't work or a discontiguous range. You need to construct the string
which combines each area's worksheet-referenced address:

Sub ChartSeriesData()
Dim rngData As Range
Dim rArea As Range
Dim sAddress As String

Set rngData = ActiveSheet.Range("B5,B8,B11,B35")
sAddress = "="
For Each rArea In rngData.Areas
sAddress = sAddress & "'" & ActiveSheet.Name & "'!" & rArea.Address(, ,
xlR1C1) & ","
Next
sAddress = Left$(sAddress, Len(sAddress) - 1)
ActiveSheet.ChartObjects(1).Chart.SeriesCollection (1).XValues = sAddress

End Sub

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


"JLGWhiz" wrote in message
...
The syntax for a chart series would be:

.SeriesCollection(1).XValues = Sheets(1).Range("B5, B8, B11, B35")

"Roland" wrote:

I want to create a chart with 1 serie which has data from 4 discontiguous
cells.
I defined 'b=6' but in practice it has a variable value, also counter has
variable values.
I tried two methods:
1/ with the union method to make a multirange selection
2/ by combining the cell addresses to a string.
None of these works. How do I solve this?

thanx in advance

Sub Macro1()
Charts.Add
With ActiveChart
.ChartType = xlColumnClustered
.SetSourceData Source:=Sheets("Summery").Range("A21:I40"),
PlotBy:=xlRows
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = "={""x1"",""x2"",""x3"",""x4""}"

Set temprange = Range(Cells(2, b))
For counter = 4 To 8 Step 2
Set temprange = Union(temprange, Range(Cells(counter, b)))
Next
.SeriesCollection(1).Values = temprange

'tempstring = Cells(2, b).Address
'For counter = 4 To 8 Step 2
' tempstring = tempstring & "," & Cells(counter, b).Address
'Next
'.SeriesCollection(1).Values = range(tempstring)

.SeriesCollection(1).Name = "=""test"""
.Location Whe=xlLocationAsObject, Name:="Summery"
End With
End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Discontiguous Chart Source

What's a pain is that you can refer to a range fine with this syntax, but it
doesn't work for a chart.

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


"JLGWhiz" wrote in message
...
Now I remember why I do most of my charts manually and just use VBA to
call
them up. Thanks for the lesson Jon.

"Jon Peltier" wrote:

That doesn't work or a discontiguous range. You need to construct the
string
which combines each area's worksheet-referenced address:

Sub ChartSeriesData()
Dim rngData As Range
Dim rArea As Range
Dim sAddress As String

Set rngData = ActiveSheet.Range("B5,B8,B11,B35")
sAddress = "="
For Each rArea In rngData.Areas
sAddress = sAddress & "'" & ActiveSheet.Name & "'!" & rArea.Address(,
,
xlR1C1) & ","
Next
sAddress = Left$(sAddress, Len(sAddress) - 1)
ActiveSheet.ChartObjects(1).Chart.SeriesCollection (1).XValues =
sAddress

End Sub

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


"JLGWhiz" wrote in message
...
The syntax for a chart series would be:

.SeriesCollection(1).XValues = Sheets(1).Range("B5, B8, B11, B35")

"Roland" wrote:

I want to create a chart with 1 serie which has data from 4
discontiguous
cells.
I defined 'b=6' but in practice it has a variable value, also counter
has
variable values.
I tried two methods:
1/ with the union method to make a multirange selection
2/ by combining the cell addresses to a string.
None of these works. How do I solve this?

thanx in advance

Sub Macro1()
Charts.Add
With ActiveChart
.ChartType = xlColumnClustered
.SetSourceData Source:=Sheets("Summery").Range("A21:I40"),
PlotBy:=xlRows
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = "={""x1"",""x2"",""x3"",""x4""}"

Set temprange = Range(Cells(2, b))
For counter = 4 To 8 Step 2
Set temprange = Union(temprange, Range(Cells(counter, b)))
Next
.SeriesCollection(1).Values = temprange

'tempstring = Cells(2, b).Address
'For counter = 4 To 8 Step 2
' tempstring = tempstring & "," & Cells(counter, b).Address
'Next
'.SeriesCollection(1).Values = range(tempstring)

.SeriesCollection(1).Name = "=""test"""
.Location Whe=xlLocationAsObject, Name:="Summery"
End With
End Sub






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
Discontiguous Chart Source Ladymuck Excel Programming 6 January 2nd 07 10:47 AM
Items in a discontiguous range [email protected] Excel Programming 2 December 1st 06 08:42 AM
Is it possible to plot discontiguous cells? Peter Bernadyne Charts and Charting in Excel 8 May 11th 06 09:45 PM
Is it possible to plot discontiguous cells? Peter Bernadyne Excel Discussion (Misc queries) 0 May 9th 06 10:32 PM
discontiguous ranges in charts Pilgrim Excel Programming 1 July 3rd 04 05:53 PM


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

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

About Us

"It's about Microsoft Excel"