我正在寻找一些通过VBA更改图表X轴刻度线的帮助。我目前有以下图表。理想情况下,我希望减少刻度线和日期的格式,使它们显示为“ 04 Nov 2019”。任何帮助表示赞赏!
Sub CreateChart()
'PURPOSE: Create a chart (chart dimensions are not required)
Dim rng As Range
Dim cht As Object
Dim wks As Worksheet, wks2 As Worksheet
Set wks = Sheet1
Set wks2 = Sheet5
'Your data range for the chart
LastRow = wks.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
Set rng = wks.Range(wks.Cells(1, 2), wks.Cells(LastRow, 7))
'Create a chart
'Create a chart
Set cht = wks2.ChartObjects.Add( _
Left:=wks2.Range("A6").Left, _
Width:=495, _
Top:=wks2.Range("A6").Top, _
Height:=380)
'Give chart some data
'cht.Chart.SetSourceData Source:=rng
cht.Chart.SetSourceData Source:=wks.Range(wks.Cells(1, 3), wks.Cells(LastRow, 7))
' Add lines
cht.Chart.SeriesCollection(1).XValues = wks.Range(wks.Cells(1, 2), wks.Cells(LastRow, 2))
'Determine the chart type
cht.Chart.ChartType = xlLine
'Ensure chart has a title
cht.Chart.HasTitle = True
'Change chart's title
cht.Chart.ChartTitle.Text = "Polling Intentions (YouGovData)"
'Change colours
cht.Chart.SeriesCollection.Item(1).Format.Line.ForeColor.RGB = RGB(0, 0, 255)
cht.Chart.SeriesCollection.Item(2).Format.Line.ForeColor.RGB = RGB(255, 0, 0)
cht.Chart.SeriesCollection.Item(3).Format.Line.ForeColor.RGB = RGB(255, 220, 0)
cht.Chart.SeriesCollection.Item(4).Format.Line.ForeColor.RGB = RGB(244, 183, 69)
cht.Chart.SeriesCollection.Item(5).Format.Line.ForeColor.RGB = RGB(0, 216, 254)
cht.Chart.Parent.Name = "PollTable"
End Sub