LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Change colour of bars/lines in charts when data in rows/colums

Hi Everyone,

I'm putting together some vb code to change the colours of the bars or lines
on a chart in one go. I've set it up so far for when the data is in rows (ie
the individual series lie along the x axis). However, I need to consider how
to cycle through the data points for when it is in columns, which essentially
means I need to search for xlcategory names and the relavent points (I
think). I suppose I also need to consider other types of charts and so would
also be grateful for any guidance in how to best do this (as I presume you
can't use the 'interior' object for when using lines!).

Here's the code I've written which works fine for when data is in rows.
Below also is the data I've used.

-----------------------

Sub SetChartColoursForMults()

Dim Chartobj As Chart
Dim s As series
Dim pt As Point

On Error GoTo error_it
Chartname = ActiveChart.Name
On Error GoTo 0



Response = MsgBox("Please make sure you have selected the chart to change
the series colours." & Chr(10) _
& "The following Multiples will be set to the following [excel]
colours:-" & Chr(10) & Chr(10) _
& "Tesco Blue" & Chr(10) _
& "Sainsbury Orange" & Chr(10) _
& "Asda Bright Green" & Chr(10) _
& "Morrisons Black" & Chr(10) _
& "Safeway Red" & Chr(10) _
& "Somerfield Turquoise" & Chr(10) _
& "Kwik Save Pink" & Chr(10) _
& "Waitrose Green" & Chr(10) _
& "Iceland Tan" & Chr(10) _
& "C&I Gold", vbOKCancel, "Set Chart Colours for Multiples")
If Response = vbCancel Then Exit Sub

With ActiveChart

For Each s In .SeriesCollection
seriesname = s.Name

Select Case seriesname 'for when data is in rows
Case "Tesco": NewCol = 5 'Blue or could use vbblue
Case "Sainsbury": NewCol = 46 'Orange
Case "Asda": NewCol = 4 'Bright Green
Case "Morrisons": NewCol = 1 'Black
Case "Safeway": NewCol = 3 'Red
Case "Somerfield": NewCol = 28 'Turquoise
Case "Kwik Save": NewCol = 26 'Pink
Case "Waitrose": NewCol = 10 'Green
Case "Iceland": NewCol = 40 'Tan
Case "C&I": NewCol = 44 'Gold
End Select

With s.Interior
.ColorIndex = NewCol
.Pattern = xlSolid
End With

' plus need to check for columns when data is in coloumns
' hmmm how do i do this?!

Next

End With


Exit Sub

error_it:
Select Case Err
Case 91
MsgBox "Please select a chart!", vbOKOnly, "Set Chart Colours for
Multiples"
Case Else
MsgBox "There is a problem! Error code: " & Err & Chr(10) &
Err.Description
End Select

End Sub

-------------------

Data:

Multiples sales '04 sale '05
Tesco 23 34
Sainsbury 34 56
Asda 56 56
Morrisons 68 45
Safeway 65 23
Somerfield 32 34
Kwik Save 34 56
Waitrose 56 68
Iceland 56 65
C&I 45 32

Thanks in advance for your help.

<<<<<<<<<<<<STOP PRESS

Hiya,

Update for you all,

I've managed to get a bit further on the code ie testing for xlrows /
xlcolumns by using the plotby command. However I'm still stuck on getting
the corresponding x axis category label / value for that particular point.
Can anyone help?

Many thanks

RodP

 
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
how do you change bars into lines on a chart BJ Charts and Charting in Excel 1 February 16th 06 10:14 PM
How can I change a graph with 2 bars,2 lines to 3 bars, 1 line? IOWAJulie Charts and Charting in Excel 3 October 19th 05 11:13 PM
How do I change bars into just lines on a bar graph? siobhanlw Charts and Charting in Excel 1 September 13th 05 09:43 PM
How do I change a data series from bars to lines in an Excel char. mrocke Charts and Charting in Excel 1 March 29th 05 01:41 AM
Macro & Command Key to change data from Colums to rows Danno[_5_] Excel Programming 3 June 10th 04 02:53 PM


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