Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default help new to vba - charts??

I have a chart on a work sheet, and the sheet is called "Operator
Input" and the charts name is "rate"

My question is - How do i select the chart?

i have tried this

ActiveSheet.ChartObjects("rate").Select

and i get an error

but this seems to work

ActiveSheet.ChartObjects("rate").Activate

is the Activate the only way to do the selection??


Thanks in advance

Vickie


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default help new to vba - charts??

Vickie,

I believe both should work.
However, you will be much happier by not trying to select the chart,
but by setting an object reference to the chart and using the object
reference to do things.

Also, the syntax for a chart on a Worksheet and a separate Chart Sheet are different.
A chart on a worksheet in contained within a ChartObject. A chart sheet is a chart.
If that doesn't make sense, then I believe that was Microsoft's intent.<g

Take a look at the following example, that changes the background color
of a chart on a worksheet. It should work on the first chart shown on
the active worksheet (including your "rate" chart).
(Be aware that there is a separate newsgroup devoted only to charts...
"microsoft.public.excel.charting")
'----------------------------------
Sub Test()
Dim chtRate As Excel.Chart
Dim lngColor As Long

'Make an object reference to the chart within the ChartObject
Set chtRate = ActiveSheet.ChartObjects(1).Chart

'Use the reference to determine the Chartarea color
lngColor = chtRate.ChartArea.Interior.ColorIndex

'Change the chartarea color
chtRate.ChartArea.Interior.ColorIndex = 40

MsgBox "Chart color changed "

'Return the chartarea color back to original color.
chtRate.ChartArea.Interior.ColorIndex = lngColor

Set chtRate = Nothing
End Sub
'----------------------------------

Regards,
Jim Cone
San Francisco, USA


"vickie_raven" wrote in message
...
I have a chart on a work sheet, and the sheet is called "Operator
Input" and the charts name is "rate"
My question is - How do i select the chart?
i have tried this
ActiveSheet.ChartObjects("rate").Select
and i get an error
but this seems to work
ActiveSheet.ChartObjects("rate").Activate
is the Activate the only way to do the selection??
Thanks in advance
Vickie


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default help new to vba - charts??

Jim

Thank you so much for taking the time to help me!!!
I am working with your example now.

Thank you again!!

Vickie





On Sun, 27 Feb 2005 16:47:27 -0800, "Jim Cone"
wrote:

Vickie,

I believe both should work.
However, you will be much happier by not trying to select the chart,
but by setting an object reference to the chart and using the object
reference to do things.

Also, the syntax for a chart on a Worksheet and a separate Chart Sheet are different.
A chart on a worksheet in contained within a ChartObject. A chart sheet is a chart.
If that doesn't make sense, then I believe that was Microsoft's intent.<g

Take a look at the following example, that changes the background color
of a chart on a worksheet. It should work on the first chart shown on
the active worksheet (including your "rate" chart).
(Be aware that there is a separate newsgroup devoted only to charts...
"microsoft.public.excel.charting")
'----------------------------------
Sub Test()
Dim chtRate As Excel.Chart
Dim lngColor As Long

'Make an object reference to the chart within the ChartObject
Set chtRate = ActiveSheet.ChartObjects(1).Chart

'Use the reference to determine the Chartarea color
lngColor = chtRate.ChartArea.Interior.ColorIndex

'Change the chartarea color
chtRate.ChartArea.Interior.ColorIndex = 40

MsgBox "Chart color changed "

'Return the chartarea color back to original color.
chtRate.ChartArea.Interior.ColorIndex = lngColor

Set chtRate = Nothing
End Sub
'----------------------------------

Regards,
Jim Cone
San Francisco, USA


"vickie_raven" wrote in message
.. .
I have a chart on a work sheet, and the sheet is called "Operator
Input" and the charts name is "rate"
My question is - How do i select the chart?
i have tried this
ActiveSheet.ChartObjects("rate").Select
and i get an error
but this seems to work
ActiveSheet.ChartObjects("rate").Activate
is the Activate the only way to do the selection??
Thanks in advance
Vickie


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default help new to vba - charts??

When trying the suggested chart area dynamic colorization with a function
invoked from a cell withing the chart's sheet, the code seems to work, yet
the color reverts to its original. Even manually modifying the chartarea
color to 40 in debug is ignored and reverts to the original 15. Any clues
would be appreciated.

Function Test()
Dim chtRate As Excel.Chart
Dim lngColor As Long

'Make an object reference to the chart within the ChartObject
Set chtRate = ActiveSheet.ChartObjects(1).Chart

'Use the reference to determine the Chartarea color
lngColor = chtRate.ChartArea.Interior.ColorIndex (works lngColor = 15)

lngColor = 40 (works lngColor = 40)

'Change the chartarea color
chtRate.ChartArea.Interior.ColorIndex = lngColor (doesn't work lngColor
remains 15)
'chtRate.ChartArea.Interior.ColorIndex = 40

'Use the reference to determine the Chartarea color
lngColor = chtRate.ChartArea.Interior.ColorIndex (after execution, both=15)


'Return the chartarea color back to original color.
'chtRate.ChartArea.Interior.ColorIndex = lngColor

'Set chtRate = Nothing
End Function

"Jim Cone" wrote:

Vickie,

I believe both should work.
However, you will be much happier by not trying to select the chart,
but by setting an object reference to the chart and using the object
reference to do things.

Also, the syntax for a chart on a Worksheet and a separate Chart Sheet are different.
A chart on a worksheet in contained within a ChartObject. A chart sheet is a chart.
If that doesn't make sense, then I believe that was Microsoft's intent.<g

Take a look at the following example, that changes the background color
of a chart on a worksheet. It should work on the first chart shown on
the active worksheet (including your "rate" chart).
(Be aware that there is a separate newsgroup devoted only to charts...
"microsoft.public.excel.charting")
'----------------------------------
Sub Test()
Dim chtRate As Excel.Chart
Dim lngColor As Long

'Make an object reference to the chart within the ChartObject
Set chtRate = ActiveSheet.ChartObjects(1).Chart

'Use the reference to determine the Chartarea color
lngColor = chtRate.ChartArea.Interior.ColorIndex

'Change the chartarea color
chtRate.ChartArea.Interior.ColorIndex = 40

MsgBox "Chart color changed "

'Return the chartarea color back to original color.
chtRate.ChartArea.Interior.ColorIndex = lngColor

Set chtRate = Nothing
End Sub
'----------------------------------

Regards,
Jim Cone
San Francisco, USA


"vickie_raven" wrote in message
...
I have a chart on a work sheet, and the sheet is called "Operator
Input" and the charts name is "rate"
My question is - How do i select the chart?
i have tried this
ActiveSheet.ChartObjects("rate").Select
and i get an error
but this seems to work
ActiveSheet.ChartObjects("rate").Activate
is the Activate the only way to do the selection??
Thanks in advance
Vickie



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default help new to vba - charts??

Correction from previous post: chtRate.ChartArea.Interior.ColorIndex =
lngColor (strike this: doesn't work lngColor remains 15) (replacement
correction: chtRate.ChartArea.Interior.ColorIndex remains 15)


"silver23" wrote:

When trying the suggested chart area dynamic colorization with a function
invoked from a cell withing the chart's sheet, the code seems to work, yet
the color reverts to its original. Even manually modifying the chartarea
color to 40 in debug is ignored and reverts to the original 15. Any clues
would be appreciated.

Function Test()
Dim chtRate As Excel.Chart
Dim lngColor As Long

'Make an object reference to the chart within the ChartObject
Set chtRate = ActiveSheet.ChartObjects(1).Chart

'Use the reference to determine the Chartarea color
lngColor = chtRate.ChartArea.Interior.ColorIndex (works lngColor = 15)

lngColor = 40 (works lngColor = 40)

'Change the chartarea color
chtRate.ChartArea.Interior.ColorIndex = lngColor (strike this: doesn't work lngColor remains 15) (replacement correction: chtRate.ChartArea.Interior.ColorIndex remains 15)
'chtRate.ChartArea.Interior.ColorIndex = 40

'Use the reference to determine the Chartarea color
lngColor = chtRate.ChartArea.Interior.ColorIndex (after execution, both=15)


'Return the chartarea color back to original color.
'chtRate.ChartArea.Interior.ColorIndex = lngColor

'Set chtRate = Nothing
End Function

"Jim Cone" wrote:

Vickie,

I believe both should work.
However, you will be much happier by not trying to select the chart,
but by setting an object reference to the chart and using the object
reference to do things.

Also, the syntax for a chart on a Worksheet and a separate Chart Sheet are different.
A chart on a worksheet in contained within a ChartObject. A chart sheet is a chart.
If that doesn't make sense, then I believe that was Microsoft's intent.<g

Take a look at the following example, that changes the background color
of a chart on a worksheet. It should work on the first chart shown on
the active worksheet (including your "rate" chart).
(Be aware that there is a separate newsgroup devoted only to charts...
"microsoft.public.excel.charting")
'----------------------------------
Sub Test()
Dim chtRate As Excel.Chart
Dim lngColor As Long

'Make an object reference to the chart within the ChartObject
Set chtRate = ActiveSheet.ChartObjects(1).Chart

'Use the reference to determine the Chartarea color
lngColor = chtRate.ChartArea.Interior.ColorIndex

'Change the chartarea color
chtRate.ChartArea.Interior.ColorIndex = 40

MsgBox "Chart color changed "

'Return the chartarea color back to original color.
chtRate.ChartArea.Interior.ColorIndex = lngColor

Set chtRate = Nothing
End Sub
'----------------------------------

Regards,
Jim Cone
San Francisco, USA


"vickie_raven" wrote in message
...
I have a chart on a work sheet, and the sheet is called "Operator
Input" and the charts name is "rate"
My question is - How do i select the chart?
i have tried this
ActiveSheet.ChartObjects("rate").Select
and i get an error
but this seems to work
ActiveSheet.ChartObjects("rate").Activate
is the Activate the only way to do the selection??
Thanks in advance
Vickie





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default help new to vba - charts??

In Subject: background-foreground color 5/26/2005 8:31 AM PST
By: silver23 In: microsoft.public.excel.charting

Jim Cone is deserving of credit for offering the basis of this solution to
chartarea colorization.

"Jim Cone" wrote:

Vickie,

I believe both should work.
However, you will be much happier by not trying to select the chart,
but by setting an object reference to the chart and using the object
reference to do things.

Also, the syntax for a chart on a Worksheet and a separate Chart Sheet are different.
A chart on a worksheet in contained within a ChartObject. A chart sheet is a chart.
If that doesn't make sense, then I believe that was Microsoft's intent.<g

Take a look at the following example, that changes the background color
of a chart on a worksheet. It should work on the first chart shown on
the active worksheet (including your "rate" chart).
(Be aware that there is a separate newsgroup devoted only to charts...
"microsoft.public.excel.charting")
'----------------------------------
Sub Test()
Dim chtRate As Excel.Chart
Dim lngColor As Long

'Make an object reference to the chart within the ChartObject
Set chtRate = ActiveSheet.ChartObjects(1).Chart

'Use the reference to determine the Chartarea color
lngColor = chtRate.ChartArea.Interior.ColorIndex

'Change the chartarea color
chtRate.ChartArea.Interior.ColorIndex = 40

MsgBox "Chart color changed "

'Return the chartarea color back to original color.
chtRate.ChartArea.Interior.ColorIndex = lngColor

Set chtRate = Nothing
End Sub
'----------------------------------

Regards,
Jim Cone
San Francisco, USA


"vickie_raven" wrote in message
...
I have a chart on a work sheet, and the sheet is called "Operator
Input" and the charts name is "rate"
My question is - How do i select the chart?
i have tried this
ActiveSheet.ChartObjects("rate").Select
and i get an error
but this seems to work
ActiveSheet.ChartObjects("rate").Activate
is the Activate the only way to do the selection??
Thanks in advance
Vickie



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
charts toolbar / charts disappeared Pro Charts and Charting in Excel 0 December 18th 09 01:31 AM
link excel charts to web pages and update charts automatically Signguy Charts and Charting in Excel 1 April 22nd 08 08:29 PM
Charts - How to have multiple charts share a legend. Sean Charts and Charting in Excel 2 November 20th 07 04:49 AM
interactive charts for stacked bar charts [email protected] Charts and Charting in Excel 4 December 28th 06 09:58 PM
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:20 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"