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

I would like to insert a pie chart where the source data is on the active
worksheet but comes from two discontiguous ranges (eg B2:C10 and B15:C15).

I have two ranges GBData, for the first range, and NonGBData for the second
range.

The following code sets the source data as B2:C15, which is incorrect. How
can I amend it to create the chart with only the data I want?

WShtName = ActiveSheet.Name
Charts.Add
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=Sheets(WShtName).Range( _
GBData.Address, NonGBData.Address), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:=WShtName

Many thanks for any suggestions, happy New Year!




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

Even manually, those ranges don't come out properly, but to get the string
you want to get:


ActiveChart.SetSourceData Source:=Sheets(WShtName).Range( _
GBData.Address & "," & NonGBData.Address)


--
Regards,
Tom Ogilvy



"Ladymuck" wrote in message
...
I would like to insert a pie chart where the source data is on the active
worksheet but comes from two discontiguous ranges (eg B2:C10 and B15:C15).

I have two ranges GBData, for the first range, and NonGBData for the
second
range.

The following code sets the source data as B2:C15, which is incorrect. How
can I amend it to create the chart with only the data I want?

WShtName = ActiveSheet.Name
Charts.Add
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=Sheets(WShtName).Range( _
GBData.Address, NonGBData.Address), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:=WShtName

Many thanks for any suggestions, happy New Year!






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

Try this in a new workbook -

Sub test2()

With Range("B2:C10")
.Name = "GBData"
.Columns(1).Value = "a"
.Columns(2).Value = 1
End With
With Range("B15:C15")
.Name = "NonGBData"
.Columns(1).Value = "B"
.Columns(2).Value = 4
End With

' above for testing, real stuff below

Dim sX As String
Dim rYvals As Range
Dim rTL As Range

Set rYvals = Union(Range("GBData").Columns(2),
Range("NonGBData").Columns(2))

sX = "=(" & Range("GBData").Columns(1).Address(, , xlR1C1, True) & ","
sX = sX & Range("NonGBData").Columns(1).Address(, , xlR1C1, True) & ")"

Set rTL = Range("e2")
With ActiveSheet.ChartObjects.Add(rTL.Left, rTL.Top, 200, 200)
With .Chart
.ChartType = xlPie
.SetSourceData _
Source:=rYvals, _
PlotBy:=xlColumns
.SeriesCollection(1).XValues = sX
' more chart properties
End With
End With

End Sub

I first tried to set the source simpy as
..Source:= Union(Range("GBData")., Range("NonGBData")

However this sets the Y-values as columns 1 of the respective ranges with no
category X labels, btw I assume XValues are in the first column-B of the
respective ranges with the y-values in column C

If you want your chart to be 'dynamic', ie to update with dynamic named
ranges, would need separate named ranges for the X & Y values, and instead
of the addresses syntax along the lines of mybook.xls!myname

Regards,
Peter T

"Ladymuck" wrote in message
...
I would like to insert a pie chart where the source data is on the active
worksheet but comes from two discontiguous ranges (eg B2:C10 and B15:C15).

I have two ranges GBData, for the first range, and NonGBData for the

second
range.

The following code sets the source data as B2:C15, which is incorrect. How
can I amend it to create the chart with only the data I want?

WShtName = ActiveSheet.Name
Charts.Add
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=Sheets(WShtName).Range( _
GBData.Address, NonGBData.Address), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:=WShtName

Many thanks for any suggestions, happy New Year!






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

I first tried to set the source simpy as
.Source:= Union(Range("GBData")., Range("NonGBData")


I wasn't thinking, that does work if the top left cell is empty

Sub test3()

With Range("B2:C10")
.Name = "GBData"
.Columns(1).Value = "a"
.Columns(2).Value = 1
.Cells(1, 1) = ""
.Cells(1, 2) = "my Pie"
End With
With Range("B15:C15")
.Name = "NonGBData"
.Columns(1).Value = "B"
.Columns(2).Value = 4
End With

Dim rTL As Range
Set rTL = Range("e2")

With ActiveSheet.ChartObjects.Add(rTL.Left, rTL.Top, 200, 200)
With .Chart
.ChartType = xlPie
.SetSourceData _
Source:=Union(Range("GBData"), Range("NonGBData")), _
PlotBy:=xlColumns
End With
End With

End Sub

Regards,
Peter T


"Peter T" <peter_t@discussions wrote in message
...
Try this in a new workbook -

Sub test2()

With Range("B2:C10")
.Name = "GBData"
.Columns(1).Value = "a"
.Columns(2).Value = 1
End With
With Range("B15:C15")
.Name = "NonGBData"
.Columns(1).Value = "B"
.Columns(2).Value = 4
End With

' above for testing, real stuff below

Dim sX As String
Dim rYvals As Range
Dim rTL As Range

Set rYvals = Union(Range("GBData").Columns(2),
Range("NonGBData").Columns(2))

sX = "=(" & Range("GBData").Columns(1).Address(, , xlR1C1, True) & ","
sX = sX & Range("NonGBData").Columns(1).Address(, , xlR1C1, True) & ")"

Set rTL = Range("e2")
With ActiveSheet.ChartObjects.Add(rTL.Left, rTL.Top, 200, 200)
With .Chart
.ChartType = xlPie
.SetSourceData _
Source:=rYvals, _
PlotBy:=xlColumns
.SeriesCollection(1).XValues = sX
' more chart properties
End With
End With

End Sub

I first tried to set the source simpy as
.Source:= Union(Range("GBData")., Range("NonGBData")

However this sets the Y-values as columns 1 of the respective ranges with

no
category X labels, btw I assume XValues are in the first column-B of the
respective ranges with the y-values in column C

If you want your chart to be 'dynamic', ie to update with dynamic named
ranges, would need separate named ranges for the X & Y values, and instead
of the addresses syntax along the lines of mybook.xls!myname

Regards,
Peter T

"Ladymuck" wrote in message
...
I would like to insert a pie chart where the source data is on the

active
worksheet but comes from two discontiguous ranges (eg B2:C10 and

B15:C15).

I have two ranges GBData, for the first range, and NonGBData for the

second
range.

The following code sets the source data as B2:C15, which is incorrect.

How
can I amend it to create the chart with only the data I want?

WShtName = ActiveSheet.Name
Charts.Add
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=Sheets(WShtName).Range( _
GBData.Address, NonGBData.Address), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:=WShtName

Many thanks for any suggestions, happy New Year!










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

Thanks for all your suggestions, I'll give them a try and let you know how I
get on!


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Discontiguous Chart Source

Thanks Tim, very simple solution and it worked a treat. Can't believe I
missed that.

Cheers!

"Tom Ogilvy" wrote:

Even manually, those ranges don't come out properly, but to get the string
you want to get:


ActiveChart.SetSourceData Source:=Sheets(WShtName).Range( _
GBData.Address & "," & NonGBData.Address)


--
Regards,
Tom Ogilvy



"Ladymuck" wrote in message
...
I would like to insert a pie chart where the source data is on the active
worksheet but comes from two discontiguous ranges (eg B2:C10 and B15:C15).

I have two ranges GBData, for the first range, and NonGBData for the
second
range.

The following code sets the source data as B2:C15, which is incorrect. How
can I amend it to create the chart with only the data I want?

WShtName = ActiveSheet.Name
Charts.Add
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=Sheets(WShtName).Range( _
GBData.Address, NonGBData.Address), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:=WShtName

Many thanks for any suggestions, happy New Year!







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
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
Defining a discontiguous Range object Charley Kyd[_2_] Excel Programming 15 December 30th 03 12:33 AM


All times are GMT +1. The time now is 06:57 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"