asked on
ASKER
'This routine makes the panel legend using the data provided in 'vaCurItemColours' and 'vaData'
'the flag 'bTopBottom' determines the legend position
''bLegend' determins if a legend is to be created or deleted
''bShort' determines if the legend contains all the items in the DB or only those in the current data
Public Sub MakePanelLegend(Cht As Chart, bFillClear As Boolean, bTopBottom As Boolean, bLegend As Boolean, vaCurItemColours() As Variant, vaData() As Variant, bShort As Boolean)
On Error GoTo Err_MakePanelLegend
Dim shItem As Shape, stName As String
If Cht.Shapes.Count > 0 Then
For Each shItem In Cht.Shapes
shItem.Delete
Next shItem
End If
If bFillClear = False Then Cht.PlotArea.top = 58: Cht.PlotArea.Height = 486: Exit Sub
If bLegend = False Then Cht.PlotArea.top = 58: Cht.PlotArea.Height = 486: Exit Sub
If ArrayEmpty(vaData) Then Exit Sub
If rsData Is Nothing Then Exit Sub
Dim vaUsedItemColours() As Variant
If bShort Then
vaUsedItemColours = GetUsedItemColours(vaData, vaCurItemColours)
Else
vaUsedItemColours = vaCurItemColours
End If
Dim sgTop As Single, sgLeft As Single, i As Integer
Application.ScreenUpdating = False
Worksheets("Graph").Activate
ActiveSheet.ChartObjects("Chart 14").Activate
ActiveChart.ChartArea.Select
With Cht
.PlotArea.Height = 426
If bTopBottom Then
.PlotArea.top = 118
sgTop = .PlotArea.top - 30
Else
.PlotArea.top = 58
sgTop = .PlotArea.InsideTop + .PlotArea.Height
End If
sgLeft = .PlotArea.InsideLeft
For i = LBound(vaUsedItemColours) To UBound(vaUsedItemColours)
.Shapes.AddShape(msoShapeRectangle, sgLeft + (i Mod 12) * 60, sgTop + (i \ 12) * 15, 10, 10).Select
Selection.ShapeRange.Line.Visible = msoTrue
Selection.ShapeRange.Line.Weight = 0.1
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.RGB = vaUsedItemColours(i, 2)
Selection.ShapeRange.Fill.Transparency = 0#
.Shapes.AddLabel(msoTextOrientationHorizontal, sgLeft + (i Mod 12) * 60 + 10, sgTop + (i \ 12) * 15, 30, 10).Select
Selection.ShapeRange(1).TextFrame.AutoSize = msoTrue
If CStr(vaUsedItemColours(i, 0)) <> "" Then
Selection.Text = CStr(vaUsedItemColours(i, 0))
Else
Selection.Text = "Blank"
End If
With Selection.Font
.Name = "Arial"
.Size = 10
.FontStyle = "Normal"
End With
If Selection.ShapeRange(1).Width > 48 Then Selection.Font.Size = 8
Next i
.ChartArea.Select
End With
Application.ScreenUpdating = True
Exit_MakePanelLegend:
Exit Sub
Err_MakePanelLegend:
MsgBox "MakePanelLegend " & Err.Description
Resume Exit_MakePanelLegend
End Sub
Worksheets("Graph").Activate
ActiveSheet.ChartObjects("Chart 14").Activate
ActiveChart.ChartArea.Select
ASKER
ASKER
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
TRUSTED BY