Borrowed and adapted from Jim Cone's example in Subject: Re: help new to vba
- charts?? 2/27/2005 4:50 PM PST By: Jim Cone In:
microsoft.public.excel.programming
You can quickly see examples of the chartarea colors available to you by
doing the following:
1. From your sheet that contains a chart, select "Restore Down" (upper-right
on the display-screen, middle box). This displays a smaller, but adequate,
view of your chart.
2. From the display that results from step 1, open the Visual Basic Editor
under Tools, Macro, Visual Basic Editor. Or, select Alt+F11. Either should
result in the same display of the Visual Basic Editor.
3. Copy this code into the Visual Basic Editor:
Sub ColorTest()
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
'What is the current color?
lngColor = chtRate.ChartArea.Interior.ColorIndex
'Good, now make the next color
lngColor = lngColor + 1
'Show the next chartarea color
chtRate.ChartArea.Interior.ColorIndex = lngColor
Set chtRate = Nothing
End Sub
4. On the bottom of your PC display, left-click the Microsoft Excel button.
This should result in your screen showing two Window items:
a) Your chart and b) the Visual Basic Editor.
5. At the top of your Visual Basic Editor window, there's an arrow pointing
right (just under the word "Debug"). When you point your mouse at it, a
"popup text" says "Run Sub/UserForm". Left-click that arrow.
6. Every time you left-click the "Run Sub/UserForm" arrow, you should see
your chart's chartarea change color. This will show you several-dozen colors
that you can use for your chartarea.
If you haven't decided what looks best, keep clicking
You will continue
to see different colors until you do.