我正在尝试将数据标签设置为自定义值。但是,它们不会出现。我已经明确定义了它们可能出现的范围,并且不知道为什么它们不出现。
Dim names As Range
Set names = Range(Range("A2"), Range("A2").End(xlDown))
Set mypts = mysrs.Points
mypts(mypts.count).ApplyDataLabels
With mypts(mypts.count).DataLabel
.ShowSeriesName = False
.ShowCategoryName = False
.ShowValue = False
' optional parameters
.Position = xlLabelPositionAbove
.Font.name = "Helvetica"
.Font.Size = 10
.Font.Bold = False
End With
For Each pt In mypts
k = k + 1
pt.DataLabel.Text = names.Cells(k, 1).Text
Next
我可以将名称作为数组传递吗?
答案 0 :(得分:0)
我发现您的代码有2个问题。您仅将标签格式应用于最后一点。其次,您没有写 .HasDataLabel = True 。尝试以下代码(注意,我假设您已经正确定义了 mysrs )
Dim names As Range
Set names = Range(Range("A2"), Range("A2").End(xlDown)
Set mypts = mysrs.Points
'mypts(mypts.Count).ApplyDataLabels
For k = 1 To mypts.Count
mypts(k).HasDataLabel = True
mypts(k).DataLabel.Text = names.Cells(k, 1).Text
With mypts(k).DataLabel
.ShowSeriesName = False
.ShowCategoryName = False
.ShowValue = False
' optional parameters
.Position = xlLabelPositionAbove
.Font.Name = "Helvetica"
.Font.Size = 10
.Font.Bold = False
End With
Next k
希望这有帮助