以下代码的问题是这个。我有雷达图表和条形图。我希望雷达图表缺失值的间隙,因此,我需要删除单元格中的值以获得间隙,但是当我删除单元格值时,条形图的标签会丢失。我试图创建一个新标签并对齐它,但它不起作用。
Option Explicit
Sub ChangeChartText()
Dim myChartObject As ChartObject
Dim mySrs As Series
Dim myPts As Points
Dim ws As Worksheet, x, vals
Dim cht As Chart, s As Series, p As Point, y, z
For Each ws In ActiveWorkbook.Worksheets
If Left(ws.name, 4) = "Page" Then
With ws
'For Each myChartObject In ws.ChartObjects
' For Each mySrs In myChartObject.Chart.SeriesCollection
For y = 1 To ws.ChartObjects.Count
Set cht = ws.ChartObjects(y).Chart
For z = 1 To cht.SeriesCollection.Count
Set s = cht.SeriesCollection(z)
vals = s.Values
For x = LBound(vals) To UBound(vals)
On Error Resume Next
If Not s.Points(x).DataLabel.Text Is Nothing Then
If IsEmpty(vals(x)) Then
s.Points(x).HasDataLabel = True
s.Points(x).DataLabel.Text = "N\A"
With s.Points(x).DataLabel
.HorizontalAlignment = xlTop
.VerticalAlignment = xlTop
.ReadingOrder = xlLTR
.Position = xlLabelPositionAbove
.Orientation = xlHorizontal
End With
ElseIf s.Points(x).DataLabel.Text = "N\A" And vals(x) <> 0 Then
s.Points(x).DataLabel.AutoText = True
End If
End If
Next x
Next z
Next y
' Next mySrs
'Next myChartObject
End With
End If
Next ws
End Sub