请运行以下代码。
Public Sub Macro1()
'Delete all charts
For i = ActiveSheet.Shapes.Count To 1 Step -1
If ActiveSheet.Shapes(i).Type = msoChart Then
ActiveSheet.Shapes(i).Delete
End If
Next i
'Add a chart.
With ActiveSheet.ChartObjects.Add(Left:=10, Top:=10, Width:=400, Height:=200)
.Name = "myChart"
End With
'Add a serie.
With ActiveSheet.ChartObjects("myChart").Chart.SeriesCollection.NewSeries
.ChartType = xlLine
.XValues = Array(45658, 45689, 45717, 45748, 45778, 45809)
.Values = Array(1, 2, 3, 4, 5, 6)
End With
'Format the xlCategory
With ActiveSheet.ChartObjects("myChart").Chart.Axes(xlCategory)
.CategoryType = xlTimeScale
.TickLabels.NumberFormat = "MMM/YY"
End With
End Sub
如何通过 vba在图表的 Y 轴上显示大写月份名称?
下图显示了所需的输出。
修改这个块:
并删除最后一个:
'Format the xlCategory
。