Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Coloring Chart Area Dynamically?

Cell A82 can be one of two values; either zero(0) or one(1). And changes
from one day to the next because it's derived from several other cells that
change daily.

I have four line charts on four sheets based on data in the one numbers sheet.

These were manually colored with white chart areas. And white plot areas.

Is there a macro available that would color the four chart areas only yellow
if cell A82 is one and color white chart areas if cell A82 is zero?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Coloring Chart Area Dynamically?

Maybe with a sheet calculate event on the numbers sheet:

Private Sub Worksheet_Calculate()
Dim chrt As Chart
For Each chrt In ActiveWorkbook.Charts
If Me.Range("A82").Value = 1 Then
chrt.ChartArea.Interior.ColorIndex = 36
Else
chrt.ChartArea.Interior.ColorIndex = xlAutomatic
End If
Next chrt
End Sub

This is worksheet event code. Right click the numbers sheet tab, select
View Code and paste the code in there.

Hope this helps
Rowan

silver23 wrote:
Cell A82 can be one of two values; either zero(0) or one(1). And changes
from one day to the next because it's derived from several other cells that
change daily.

I have four line charts on four sheets based on data in the one numbers sheet.

These were manually colored with white chart areas. And white plot areas.

Is there a macro available that would color the four chart areas only yellow
if cell A82 is one and color white chart areas if cell A82 is zero?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Coloring Chart Area Dynamically?

Thank you. When I debug the macro and step into the first statement "For
Each chrt..." however, Expression = chrt, Value = Nothing, Type = Chart.
Then the macro exits.

"Rowan Drummond" wrote:

Maybe with a sheet calculate event on the numbers sheet:

Private Sub Worksheet_Calculate()
Dim chrt As Chart
For Each chrt In ActiveWorkbook.Charts
If Me.Range("A82").Value = 1 Then
chrt.ChartArea.Interior.ColorIndex = 36
Else
chrt.ChartArea.Interior.ColorIndex = xlAutomatic
End If
Next chrt
End Sub

This is worksheet event code. Right click the numbers sheet tab, select
View Code and paste the code in there.

Hope this helps
Rowan

silver23 wrote:
Cell A82 can be one of two values; either zero(0) or one(1). And changes
from one day to the next because it's derived from several other cells that
change daily.

I have four line charts on four sheets based on data in the one numbers sheet.

These were manually colored with white chart areas. And white plot areas.

Is there a macro available that would color the four chart areas only yellow
if cell A82 is one and color white chart areas if cell A82 is zero?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Coloring Chart Area Dynamically?

How do you ensure the charts are found when executing the macro?

"silver23" wrote:

Thank you. When I debug the macro and step into the first statement "For
Each chrt..." however, Expression = chrt, Value = Nothing, Type = Chart.
Then the macro exits.

"Rowan Drummond" wrote:

Maybe with a sheet calculate event on the numbers sheet:

Private Sub Worksheet_Calculate()
Dim chrt As Chart
For Each chrt In ActiveWorkbook.Charts
If Me.Range("A82").Value = 1 Then
chrt.ChartArea.Interior.ColorIndex = 36
Else
chrt.ChartArea.Interior.ColorIndex = xlAutomatic
End If
Next chrt
End Sub

This is worksheet event code. Right click the numbers sheet tab, select
View Code and paste the code in there.

Hope this helps
Rowan

silver23 wrote:
Cell A82 can be one of two values; either zero(0) or one(1). And changes
from one day to the next because it's derived from several other cells that
change daily.

I have four line charts on four sheets based on data in the one numbers sheet.

These were manually colored with white chart areas. And white plot areas.

Is there a macro available that would color the four chart areas only yellow
if cell A82 is one and color white chart areas if cell A82 is zero?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Coloring Chart Area Dynamically?

I ran this in a workbook with 4 charts each on it's own chartsheet and
it worked fine. If the charts were embeded as objects on normal
worksheets then the code would have to be more like this:

Private Sub Worksheet_Calculate()
Dim chrt As ChartObject
Dim i As Integer
For i = 1 To Sheets.Count
With Sheets(i)
For Each chrt In .ChartObjects
If IsNumeric(Me.Range("A82").Value) Then
If Me.Range("A82").Value = 1 Then
chrt.Chart.ChartArea.Interior.ColorIndex = 36
Else
chrt.Chart.ChartArea.Interior.ColorIndex _
= xlAutomatic
End If
End If
Next chrt
End With
Next i
End Sub

Hope this helps
Rowan

silver23 wrote:
How do you ensure the charts are found when executing the macro?

"silver23" wrote:


Thank you. When I debug the macro and step into the first statement "For
Each chrt..." however, Expression = chrt, Value = Nothing, Type = Chart.
Then the macro exits.

"Rowan Drummond" wrote:


Maybe with a sheet calculate event on the numbers sheet:

Private Sub Worksheet_Calculate()
Dim chrt As Chart
For Each chrt In ActiveWorkbook.Charts
If Me.Range("A82").Value = 1 Then
chrt.ChartArea.Interior.ColorIndex = 36
Else
chrt.ChartArea.Interior.ColorIndex = xlAutomatic
End If
Next chrt
End Sub

This is worksheet event code. Right click the numbers sheet tab, select
View Code and paste the code in there.

Hope this helps
Rowan

silver23 wrote:

Cell A82 can be one of two values; either zero(0) or one(1). And changes
from one day to the next because it's derived from several other cells that
change daily.

I have four line charts on four sheets based on data in the one numbers sheet.

These were manually colored with white chart areas. And white plot areas.

Is there a macro available that would color the four chart areas only yellow
if cell A82 is one and color white chart areas if cell A82 is zero?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Coloring Chart Area Dynamically?

Excellent! Thanks!
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Coloring Chart Area Dynamically?

Rowan,

Hi! I know you responded to this long ago, but this is really helping me. I
used your code, but it only changes the color when I execure the code via the
VB Tool. When I save the macro into the sheet and re-open it, it does not
change the color accordingly.

please help,
justin



"Rowan Drummond" wrote:

Maybe with a sheet calculate event on the numbers sheet:

Private Sub Worksheet_Calculate()
Dim chrt As Chart
For Each chrt In ActiveWorkbook.Charts
If Me.Range("A82").Value = 1 Then
chrt.ChartArea.Interior.ColorIndex = 36
Else
chrt.ChartArea.Interior.ColorIndex = xlAutomatic
End If
Next chrt
End Sub

This is worksheet event code. Right click the numbers sheet tab, select
View Code and paste the code in there.

Hope this helps
Rowan

silver23 wrote:
Cell A82 can be one of two values; either zero(0) or one(1). And changes
from one day to the next because it's derived from several other cells that
change daily.

I have four line charts on four sheets based on data in the one numbers sheet.

These were manually colored with white chart areas. And white plot areas.

Is there a macro available that would color the four chart areas only yellow
if cell A82 is one and color white chart areas if cell A82 is zero?


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
Resize chart area without resizing plot area Janwillem van Dijk Charts and Charting in Excel 2 August 2nd 05 01:52 AM
Resize chart area without resizing plot area Janwillem van Dijk[_2_] Excel Programming 2 August 2nd 05 01:52 AM
How to Dynamically Set Print Area Jerry B Excel Discussion (Misc queries) 2 February 1st 05 11:21 PM
Dynamically setting Print Area Kevin Excel Programming 3 September 24th 04 08:11 PM
Excel 2000 Dynamically Set Print Area Tom Farrell Excel Programming 1 December 5th 03 08:23 AM


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