PC Review


Reply
Thread Tools Rate Thread

error in legendentry

 
 
Mick Turner
Guest
Posts: n/a
 
      14th Dec 2005
hello,

I have a chart that needs more legend entries than can be visible shown
in the chart.

When I try to access (= change color with Interior.Colorindex) the
legend entry, an error occurs (Unable to get the LegendKey property of
the LegendEntry class). Is this due to fact that the LegendEntry in
question is not "visible"?

If I decrease the number of LegendEntries, my macro will execute perfectly.

Here's my code:

Sub ColorMacro()
Dim minVoltage As Double
Dim maxVoltage As Double
Dim i As Integer

Charts("Voltage chart").Activate

minVoltage = ActiveChart.Axes(xlValue).MinimumScale
maxVoltage = ActiveChart.Axes(xlValue).MaximumScale

'changes the scale of the legend
With ActiveChart.Axes(xlValue)
.MinimumScale = 0
If maxVoltage <= 15 Then
.MaximumScale = 15
Else
.MaximumScale = maxVoltage
End If
.MajorUnit = 0.5
End With

'loop through legend entries
For i = 1 To ActiveChart.Legend.LegendEntries.Count
ActiveChart.Legend.LegendEntries(i).LegendKey.Select
If i = 1 Then
With Selection.Interior
.ColorIndex = 4
End With
End If
If i >= 2 And i <= 9 Then
With Selection.Interior
.ColorIndex = 6
End With
End If
If i >= 10 And i <= 20 Then
With Selection.Interior
.ColorIndex = 45
End With
End If
If i > 20 Then
With Selection.Interior
.ColorIndex = 3
End With
End If
Next
End Sub

Note that my code is not finished yet. What I'm trying to do is to
change the legend maximum and minimum values (to 0 and 15, or if voltage
is higher, then that value) and change the colours so that the first
legendkey (0-0.5) has one colour, a couple of next legendkeys has
another and so on.

I would also like to delete some of the legend entries so that only one
is shown per colour. And moreover, if possible, I would like to change
the texts of the legend entries manually through VBA, but I guess that
is not possible.

I would appreciate any help!

Thanks in advance,
Mike
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
recreate a deleted LegendEntry xlrotor Microsoft Excel Programming 2 19th Mar 2008 03:37 AM
How to delete a specific LegendEntry? Intuitive Analyst Microsoft Excel Charting 4 29th Jan 2008 04:21 PM
Error, Error, Error. JohnMc Windows XP Basics 0 22nd Dec 2003 12:22 AM
A runtime error has occured. Do you want to debug? Line: 1 Error: syntax error Eric Windows XP Networking 0 24th Nov 2003 04:45 PM
IE 6 RunTime error / Line: 335 / Error: Unspecified Error kwloch Windows XP Internet Explorer 0 27th Sep 2003 02:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:03 AM.