Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 96
Default Conditional Format Bar Chart

I have a bar chart that I would like to format the color depending on the
value in the data range.

If the value of the data point is 1 I'd like to format the bar in the chart
red, if the value is 2 then blue, if the value is 3 then gold and if the
value is 4 then green.

I read some earlier posts and I feel more comfotabel using some vba in order
to complete this.

I did try to use a function posted in an answer to another question but I
get the following error at this line " Set Pts =
ActiveChart.SeriesCollection(1).Points(Cnt)": Run Time Error 91

Here is the code:

Sub ColorBars()

Application.ScreenUpdating = False

Dim Rng As Range
Dim Cnt As Integer

Cnt = 1

For Each Rng In Range("G66:G77")
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt)
If Rng.Value = "1" Then
Pts.Interior.ColorIndex = 24
ElseIf Rng.Value = "3" Then
Pts.Interior.ColorIndex = 15
ElseIf Rng.Value = "4" Then
Pts.Interior.ColorIndex = 19
End If
Cnt = Cnt + 1
Next Rng
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 6,582
Default Conditional Format Bar Chart

You don't really need VBA:
http://peltiertech.com/Excel/Charts/...nalChart1.html

If you really want to use VBA, here is a technique:
http://peltiertech.com/WordPress/vba...arts-by-value/

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Qaspec" wrote in message
...
I have a bar chart that I would like to format the color depending on the
value in the data range.

If the value of the data point is 1 I'd like to format the bar in the
chart
red, if the value is 2 then blue, if the value is 3 then gold and if the
value is 4 then green.

I read some earlier posts and I feel more comfotabel using some vba in
order
to complete this.

I did try to use a function posted in an answer to another question but I
get the following error at this line " Set Pts =
ActiveChart.SeriesCollection(1).Points(Cnt)": Run Time Error 91

Here is the code:

Sub ColorBars()

Application.ScreenUpdating = False

Dim Rng As Range
Dim Cnt As Integer

Cnt = 1

For Each Rng In Range("G66:G77")
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt)
If Rng.Value = "1" Then
Pts.Interior.ColorIndex = 24
ElseIf Rng.Value = "3" Then
Pts.Interior.ColorIndex = 15
ElseIf Rng.Value = "4" Then
Pts.Interior.ColorIndex = 19
End If
Cnt = Cnt + 1
Next Rng
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 96
Default Conditional Format Bar Chart

I get a run time error 91 at the following line

With ActiveChart.SeriesCollection(1)

Is there a specific item in reference library I need to add?

"Jon Peltier" wrote:

You don't really need VBA:
http://peltiertech.com/Excel/Charts/...nalChart1.html

If you really want to use VBA, here is a technique:
http://peltiertech.com/WordPress/vba...arts-by-value/

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Qaspec" wrote in message
...
I have a bar chart that I would like to format the color depending on the
value in the data range.

If the value of the data point is 1 I'd like to format the bar in the
chart
red, if the value is 2 then blue, if the value is 3 then gold and if the
value is 4 then green.

I read some earlier posts and I feel more comfotabel using some vba in
order
to complete this.

I did try to use a function posted in an answer to another question but I
get the following error at this line " Set Pts =
ActiveChart.SeriesCollection(1).Points(Cnt)": Run Time Error 91

Here is the code:

Sub ColorBars()

Application.ScreenUpdating = False

Dim Rng As Range
Dim Cnt As Integer

Cnt = 1

For Each Rng In Range("G66:G77")
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt)
If Rng.Value = "1" Then
Pts.Interior.ColorIndex = 24
ElseIf Rng.Value = "3" Then
Pts.Interior.ColorIndex = 15
ElseIf Rng.Value = "4" Then
Pts.Interior.ColorIndex = 19
End If
Cnt = Cnt + 1
Next Rng
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 6,582
Default Conditional Format Bar Chart

Error numbers are not nearly as descriptive as error messages.

Error 91 has the message "Object variable not set". The object it is looking
for is ActiveChart.

Select a chart and try again.

However, I suggest you use the non-VBA approach. It is easier to set up and
easier to debug.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Qaspec" wrote in message
...
I get a run time error 91 at the following line

With ActiveChart.SeriesCollection(1)

Is there a specific item in reference library I need to add?

"Jon Peltier" wrote:

You don't really need VBA:
http://peltiertech.com/Excel/Charts/...nalChart1.html

If you really want to use VBA, here is a technique:
http://peltiertech.com/WordPress/vba...arts-by-value/

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Qaspec" wrote in message
...
I have a bar chart that I would like to format the color depending on
the
value in the data range.

If the value of the data point is 1 I'd like to format the bar in the
chart
red, if the value is 2 then blue, if the value is 3 then gold and if
the
value is 4 then green.

I read some earlier posts and I feel more comfotabel using some vba in
order
to complete this.

I did try to use a function posted in an answer to another question but
I
get the following error at this line " Set Pts =
ActiveChart.SeriesCollection(1).Points(Cnt)": Run Time Error 91

Here is the code:

Sub ColorBars()

Application.ScreenUpdating = False

Dim Rng As Range
Dim Cnt As Integer

Cnt = 1

For Each Rng In Range("G66:G77")
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt)
If Rng.Value = "1" Then
Pts.Interior.ColorIndex = 24
ElseIf Rng.Value = "3" Then
Pts.Interior.ColorIndex = 15
ElseIf Rng.Value = "4" Then
Pts.Interior.ColorIndex = 19
End If
Cnt = Cnt + 1
Next Rng
End Sub






  #5   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 96
Default Conditional Format Bar Chart

I assigned the macro to the chart and click the chart in order to run the
macro. How do I activate the chart in that case?

"Jon Peltier" wrote:

Error numbers are not nearly as descriptive as error messages.

Error 91 has the message "Object variable not set". The object it is looking
for is ActiveChart.

Select a chart and try again.

However, I suggest you use the non-VBA approach. It is easier to set up and
easier to debug.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Qaspec" wrote in message
...
I get a run time error 91 at the following line

With ActiveChart.SeriesCollection(1)

Is there a specific item in reference library I need to add?

"Jon Peltier" wrote:

You don't really need VBA:
http://peltiertech.com/Excel/Charts/...nalChart1.html

If you really want to use VBA, here is a technique:
http://peltiertech.com/WordPress/vba...arts-by-value/

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Qaspec" wrote in message
...
I have a bar chart that I would like to format the color depending on
the
value in the data range.

If the value of the data point is 1 I'd like to format the bar in the
chart
red, if the value is 2 then blue, if the value is 3 then gold and if
the
value is 4 then green.

I read some earlier posts and I feel more comfotabel using some vba in
order
to complete this.

I did try to use a function posted in an answer to another question but
I
get the following error at this line " Set Pts =
ActiveChart.SeriesCollection(1).Points(Cnt)": Run Time Error 91

Here is the code:

Sub ColorBars()

Application.ScreenUpdating = False

Dim Rng As Range
Dim Cnt As Integer

Cnt = 1

For Each Rng In Range("G66:G77")
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt)
If Rng.Value = "1" Then
Pts.Interior.ColorIndex = 24
ElseIf Rng.Value = "3" Then
Pts.Interior.ColorIndex = 15
ElseIf Rng.Value = "4" Then
Pts.Interior.ColorIndex = 19
End If
Cnt = Cnt + 1
Next Rng
End Sub









  #6   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 6,582
Default Conditional Format Bar Chart

ActiveSheet.ChartObjects(Application.Caller).Activ ate

Application.Caller is the shape/chartobject that contains the chart.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Qaspec" wrote in message
...
I assigned the macro to the chart and click the chart in order to run the
macro. How do I activate the chart in that case?

"Jon Peltier" wrote:

Error numbers are not nearly as descriptive as error messages.

Error 91 has the message "Object variable not set". The object it is
looking
for is ActiveChart.

Select a chart and try again.

However, I suggest you use the non-VBA approach. It is easier to set up
and
easier to debug.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Qaspec" wrote in message
...
I get a run time error 91 at the following line

With ActiveChart.SeriesCollection(1)

Is there a specific item in reference library I need to add?

"Jon Peltier" wrote:

You don't really need VBA:
http://peltiertech.com/Excel/Charts/...nalChart1.html

If you really want to use VBA, here is a technique:
http://peltiertech.com/WordPress/vba...arts-by-value/

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Qaspec" wrote in message
...
I have a bar chart that I would like to format the color depending on
the
value in the data range.

If the value of the data point is 1 I'd like to format the bar in
the
chart
red, if the value is 2 then blue, if the value is 3 then gold and if
the
value is 4 then green.

I read some earlier posts and I feel more comfotabel using some vba
in
order
to complete this.

I did try to use a function posted in an answer to another question
but
I
get the following error at this line " Set Pts =
ActiveChart.SeriesCollection(1).Points(Cnt)": Run Time Error 91

Here is the code:

Sub ColorBars()

Application.ScreenUpdating = False

Dim Rng As Range
Dim Cnt As Integer

Cnt = 1

For Each Rng In Range("G66:G77")
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt)
If Rng.Value = "1" Then
Pts.Interior.ColorIndex = 24
ElseIf Rng.Value = "3" Then
Pts.Interior.ColorIndex = 15
ElseIf Rng.Value = "4" Then
Pts.Interior.ColorIndex = 19
End If
Cnt = Cnt + 1
Next Rng
End Sub









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
Conditional Format of a Line Chart? Kim Charts and Charting in Excel 1 March 14th 08 06:47 PM
Conditional format - gant chart Steen Excel Discussion (Misc queries) 2 January 4th 07 09:26 PM
Conditional Format - Format Transfer To Chart ju1eshart Excel Discussion (Misc queries) 0 June 1st 06 02:46 PM
Chart - conditional format digicat Charts and Charting in Excel 1 May 20th 06 11:42 AM
Can I conditional format a chart? David Polister Charts and Charting in Excel 1 November 28th 05 10:53 PM


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