PC Review


Reply
Thread Tools Rate Thread

Chart Variables

 
 
Steph
Guest
Posts: n/a
 
      30th Aug 2008
I am using Excel 2003. I'm using "Option Explicit" to force variable
declaration. I want to tie the axes of a chart that I have named "MyChart"
to worksheet cells. I've been working with the following but continue to get
errors:

Dim Cht as ChartObject

Set Cht = Worksheets("Model").ChartObjects("MyChart").Chart

With Cht.Axes(xlValue)
.MaximumScale = Sheets("Charts").Range("C7")
.MinimumScale = Sheets("Charts").Range("C9")
.MajorUnit = Sheets("Charts").Range("C8")
End With

If I take out the "Option Explicit" I can get things to work. However, I
would like to keep it in my code to help make sure I am declaring variables
correctly.

Can anyone advise as to what I am doing wrong? Thank you in advance for
your help.

--
Steph
 
Reply With Quote
 
 
 
 
Francois L
Guest
Posts: n/a
 
      30th Aug 2008
Steph a écrit :

Hi

To me, Cht is a Chart, not a ChartObject

so...

Dim Cht As Chart


--
François L


> I am using Excel 2003. I'm using "Option Explicit" to force variable
> declaration. I want to tie the axes of a chart that I have named "MyChart"
> to worksheet cells. I've been working with the following but continue to get
> errors:
>
> Dim Cht as ChartObject
>
> Set Cht = Worksheets("Model").ChartObjects("MyChart").Chart
>
> With Cht.Axes(xlValue)
> .MaximumScale = Sheets("Charts").Range("C7")
> .MinimumScale = Sheets("Charts").Range("C9")
> .MajorUnit = Sheets("Charts").Range("C8")
> End With
>
> If I take out the "Option Explicit" I can get things to work. However, I
> would like to keep it in my code to help make sure I am declaring variables
> correctly.
>
> Can anyone advise as to what I am doing wrong? Thank you in advance for
> your help.
>

 
Reply With Quote
 
Andy Pope
Guest
Posts: n/a
 
      30th Aug 2008
Hi,

You have declared the object variable Cht as ChartObject but when
setting the reference to it you actually drill further down the object
model and reference the Chart.

Either change the declaration to,

Dim Cht As Chart

Or the way you set the reference and then use it,

Set Cht = Worksheets("Model").ChartObjects("MyChart")

With Cht.Chart.Axes(xlValue)

Cheers
Andy

Steph wrote:
> I am using Excel 2003. I'm using "Option Explicit" to force variable
> declaration. I want to tie the axes of a chart that I have named "MyChart"
> to worksheet cells. I've been working with the following but continue to get
> errors:
>
> Dim Cht as ChartObject
>
> Set Cht = Worksheets("Model").ChartObjects("MyChart").Chart
>
> With Cht.Axes(xlValue)
> .MaximumScale = Sheets("Charts").Range("C7")
> .MinimumScale = Sheets("Charts").Range("C9")
> .MajorUnit = Sheets("Charts").Range("C8")
> End With
>
> If I take out the "Option Explicit" I can get things to work. However, I
> would like to keep it in my code to help make sure I am declaring variables
> correctly.
>
> Can anyone advise as to what I am doing wrong? Thank you in advance for
> your help.
>


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using variables in Chart Ranges =?Utf-8?B?bmFwcndAaG90bWFpbC5jb20=?= Microsoft Excel Charting 1 9th May 2006 12:56 AM
Chart with three variables glasbergenm Microsoft Excel Charting 8 5th Feb 2006 03:54 AM
Use variables for a chart =?Utf-8?B?RnlzaA==?= Microsoft Excel Charting 4 9th Dec 2004 08:45 PM
Help with variables for chart Charles Microsoft Excel Charting 4 11th Nov 2004 09:27 PM
Re: A chart with 3 variables Jon Peltier Microsoft Excel Charting 1 30th Jul 2004 09:35 PM


Features
 

Advertising
 

Newsgroups
 


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