#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Pie Chart

I've managed to represent the following information in a pie chart using VBA
but is unable to display the information in Column A as Category Name in the
pie chart-

Column A Column B
Apples 100
Oranges 350
Pears 200
Plums 400
Mangoes 700

Can anyone please, show how to include the information in Column A as
Category Name using VBA. Thank you.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Pie Chart

I just recorded a macro; results below:
Sub Macro1()

Range("A1:B6").Select
Charts.Add
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:B6"),
PlotBy:= _
xlColumns
ActiveChart.SeriesCollection(1).Name = "=Sheet1!R1C1"
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Fruits"
End With
End Sub


Regards,
Ryan---

--
RyGuy


"Francis Ang" wrote:

I've managed to represent the following information in a pie chart using VBA
but is unable to display the information in Column A as Category Name in the
pie chart-

Column A Column B
Apples 100
Oranges 350
Pears 200
Plums 400
Mangoes 700

Can anyone please, show how to include the information in Column A as
Category Name using VBA. Thank you.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Pie Chart

Thank you for the help. I had the same result when I recorded the macro.

However, the macro does not show how to label each of the pie slices with
the fruit names in Column A.

"ryguy7272" wrote:

I just recorded a macro; results below:
Sub Macro1()

Range("A1:B6").Select
Charts.Add
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:B6"),
PlotBy:= _
xlColumns
ActiveChart.SeriesCollection(1).Name = "=Sheet1!R1C1"
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Fruits"
End With
End Sub


Regards,
Ryan---

--
RyGuy


"Francis Ang" wrote:

I've managed to represent the following information in a pie chart using VBA
but is unable to display the information in Column A as Category Name in the
pie chart-

Column A Column B
Apples 100
Oranges 350
Pears 200
Plums 400
Mangoes 700

Can anyone please, show how to include the information in Column A as
Category Name using VBA. Thank you.


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

Where do you expect the Category Labels to be displayed, in the Legend or as
Data Labels (wouldn't normally want both).

Regards,
Peter T

"Francis Ang" wrote in message
...
I've managed to represent the following information in a pie chart using
VBA
but is unable to display the information in Column A as Category Name in
the
pie chart-

Column A Column B
Apples 100
Oranges 350
Pears 200
Plums 400
Mangoes 700

Can anyone please, show how to include the information in Column A as
Category Name using VBA. Thank you.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Pie Chart

Hi Peter,

I need to display the category label as Data Label.

Thanks.

"Peter T" wrote:

Where do you expect the Category Labels to be displayed, in the Legend or as
Data Labels (wouldn't normally want both).

Regards,
Peter T

"Francis Ang" wrote in message
...
I've managed to represent the following information in a pie chart using
VBA
but is unable to display the information in Column A as Category Name in
the
pie chart-

Column A Column B
Apples 100
Oranges 350
Pears 200
Plums 400
Mangoes 700

Can anyone please, show how to include the information in Column A as
Category Name using VBA. Thank you.







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

I recorded a macro, cleaned it up a bit to remove select & activate stuff
(which you don't need when programatically creating or changing charts),
included a few fully declared object references to get the intellisense, and
ended up with something like this -

Sub test()
Dim cht As Chart
Dim sr As Series
Dim dls As DataLabels

' you've probably already got a ref to your chart so you won't need
' this first line

Set cht = ActiveSheet.ChartObjects(1).Chart ' 1st chartobject.chart on
sheet
' or if a chart sheet
' Set cht = ActiveWorkbook.Charts("Chart1")

Set sr = cht.SeriesCollection(1)

' see recorded macro for other label arg's you might want
sr.ApplyDataLabels AutoText:=True, _
ShowCategoryName:=True

Set dls = sr.DataLabels
With dls
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.ReadingOrder = xlContext
.Position = xlLabelPositionBestFit
.Orientation = xlHorizontal
End With

End Sub

Regards,
Peter T


"Francis Ang" wrote in message
...
Hi Peter,

I need to display the category label as Data Label.

Thanks.

"Peter T" wrote:

Where do you expect the Category Labels to be displayed, in the Legend or
as
Data Labels (wouldn't normally want both).

Regards,
Peter T

"Francis Ang" wrote in message
...
I've managed to represent the following information in a pie chart
using
VBA
but is unable to display the information in Column A as Category Name
in
the
pie chart-

Column A Column B
Apples 100
Oranges 350
Pears 200
Plums 400
Mangoes 700

Can anyone please, show how to include the information in Column A as
Category Name using VBA. Thank you.







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Pie Chart

Hi Peter,

Thank you very much for all your help. The code that you gave was what I
wanted. Thank you.

"Peter T" wrote:

I recorded a macro, cleaned it up a bit to remove select & activate stuff
(which you don't need when programatically creating or changing charts),
included a few fully declared object references to get the intellisense, and
ended up with something like this -

Sub test()
Dim cht As Chart
Dim sr As Series
Dim dls As DataLabels

' you've probably already got a ref to your chart so you won't need
' this first line

Set cht = ActiveSheet.ChartObjects(1).Chart ' 1st chartobject.chart on
sheet
' or if a chart sheet
' Set cht = ActiveWorkbook.Charts("Chart1")

Set sr = cht.SeriesCollection(1)

' see recorded macro for other label arg's you might want
sr.ApplyDataLabels AutoText:=True, _
ShowCategoryName:=True

Set dls = sr.DataLabels
With dls
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.ReadingOrder = xlContext
.Position = xlLabelPositionBestFit
.Orientation = xlHorizontal
End With

End Sub

Regards,
Peter T


"Francis Ang" wrote in message
...
Hi Peter,

I need to display the category label as Data Label.

Thanks.

"Peter T" wrote:

Where do you expect the Category Labels to be displayed, in the Legend or
as
Data Labels (wouldn't normally want both).

Regards,
Peter T

"Francis Ang" wrote in message
...
I've managed to represent the following information in a pie chart
using
VBA
but is unable to display the information in Column A as Category Name
in
the
pie chart-

Column A Column B
Apples 100
Oranges 350
Pears 200
Plums 400
Mangoes 700

Can anyone please, show how to include the information in Column A as
Category Name using VBA. Thank you.








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
Dynamic chart- curve dropping to zero ( chart type- Line) vmohan1978 Charts and Charting in Excel 0 February 1st 10 09:11 AM
Excel 2003 is missing Built-In Custom Chart Types in Chart Wizard Julius Charts and Charting in Excel 2 March 6th 09 04:43 PM
Excel 2003 is missing Built-In Custom Chart Types in Chart Wizard Julius Setting up and Configuration of Excel 1 March 6th 09 01:57 AM
Double-stacked Bar Chart WITH a Secondary Y Axis Line chart? lpenndorf Charts and Charting in Excel 1 February 7th 07 04:32 PM
Cannot Activate Chart Area in Chart. Chart Object Failed [email protected] Excel Programming 2 August 8th 06 02:38 AM


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