Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Excel Charts and VBA

Hello

I must be a complete Idiot but I never managed to get VBA to work with
Excel Charts. Would anyone be kind enought to show me what syntax
works with charts? I must say the "Record Macro" function doesn't
really help to generate clean codes.

Let's say I have several charts on a sheet. I would like to add a new
series to an existing XY chart (chart #2 and I don't know how many
series there are already in this chart).

So my code would start with:

Dim S as worksheet
Set S=Thisworkbook.Sheets("NameoftheSheet")
Dim Rg1 as range, Rg2 as range, Rg3 as range
Set Rg1=S.Range("TheXdata")
Set Rg2=S.Range("TheYdata")
Set Rg3=S.Range("TheChartTitle")


Would anyone be able to indicate me how to do it properly?
The "record macro" function only generates relative references to the
data. Is this the only solution (I have range names)? Does it have to
be a string or can it be a range, etc.

I thank you in advance
Charles
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Excel Charts and VBA

The examples on this page should get you started:

http://peltiertech.com/Excel/ChartsH...kChartVBA.html

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


"Charles" wrote in message
...
Hello

I must be a complete Idiot but I never managed to get VBA to work with
Excel Charts. Would anyone be kind enought to show me what syntax
works with charts? I must say the "Record Macro" function doesn't
really help to generate clean codes.

Let's say I have several charts on a sheet. I would like to add a new
series to an existing XY chart (chart #2 and I don't know how many
series there are already in this chart).

So my code would start with:

Dim S as worksheet
Set S=Thisworkbook.Sheets("NameoftheSheet")
Dim Rg1 as range, Rg2 as range, Rg3 as range
Set Rg1=S.Range("TheXdata")
Set Rg2=S.Range("TheYdata")
Set Rg3=S.Range("TheChartTitle")


Would anyone be able to indicate me how to do it properly?
The "record macro" function only generates relative references to the
data. Is this the only solution (I have range names)? Does it have to
be a string or can it be a range, etc.

I thank you in advance
Charles



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Excel Charts and VBA

Thanks but it doesn't seem to really work. For instance if I do (S
being a worksheet):

Dim TheChart As ChartObject
Set TheChart = S.ChartObjects(1)
TheChart.Chart.Select

excel will invariably throw a "Method "Select" of object "_Chart"
failed. This is the case for any method included in the "Chart"
object. However, the method directly accessible from "TheChart" work
(ex: TheChart.Select)

If I manage to get passed this error, I think I can help myself. But I
really don't know how to get around it. Would someone be able to tell
me what I am doing wrong?

thanks
Charles
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Excel Charts and VBA

and for instance this code will result in a similar error:
Dim Ch As Excel.Chart
Set Ch = S.ChartObjects(1).Chart
Ch.Select
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Excel Charts and VBA

1. You can't select a chart. You can select a chart object, and you can
select the chart area or other chart element.

2. You should be trying to make your code work without selecting the chart.
The page I cited discusses this.

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


"Charles" wrote in message
...
and for instance this code will result in a similar error:
Dim Ch As Excel.Chart
Set Ch = S.ChartObjects(1).Chart
Ch.Select





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Excel Charts and VBA

I see. Actually the two functions I was using to test were Select and
Title. Title doesn't work unless hastitle has been set on true, and
select doesn't work at all. This explains that.

thanks!
Charles
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
Unable to click on charts & unable to create any new charts Excel Snapclick Charts and Charting in Excel 4 February 1st 09 07:59 PM
link excel charts to web pages and update charts automatically Signguy Charts and Charting in Excel 1 April 22nd 08 08:29 PM
Copy/Paste Charts; Define Destination of Charts in PowerPoint ryguy7272 Excel Programming 2 January 24th 08 08:04 PM
Charts - How to have multiple charts share a legend. Sean Charts and Charting in Excel 2 November 20th 07 04:49 AM
Matching the colors Column Charts and Pie Charts RohanSewgobind Charts and Charting in Excel 3 April 21st 06 09:35 PM


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