VBA Excel Set Horizontal Axis on Chart
<p>I have compiled the following macro to create 3 charts on the right side of the Excel Worksheet. </p>

<pre><code>Sub CreateChart()
Dim objChart As ChartObject
Dim myChtRange As Range
Dim myDataRange As Range
With ActiveSheet

Set myChtRange = Range("M10:Q23")
' What range contains data for chart
Set myDataRange = ActiveSheet.ListObjects("Table2").Range
' Cover chart range with chart
Set objChart = .ChartObjects.Add( _
    Left:=myChtRange.Left, Top:=myChtRange.Top, _
    Width:=myChtRange.Width, Height:=myChtRange.Height)
' Put all the right stuff in the chart
With objChart.Chart
    .ChartArea.AutoScaleFont = False
    .ChartType = xlLine
    .ChartStyle = 245
    .SetSourceData Source:=myDataRange
    .HasTitle = True
    .HasLegend = False
    .ChartTitle.Characters.Text = "PO By Year"
    .ChartTitle.Font.Bold = True
    .ChartTitle.Font.Size = 12

    With .Axes(xlCategory, xlPrimary)
       .HasTitle = True
       With .AxisTitle
            .Characters.Text = "Year"
            .Font.Size = 10
            .Font.Bold = True
        End With
    End With
    With .Axes(xlValue, xlPrimary)
        .HasTitle = True
        .DisplayUnit = xlMillions
        .HasDisplayUnitLabel = False
        With .AxisTitle
            .Characters.Text = "Millions"
            .Font.Size = 10
            .Font.Bold = True
        End With
    End With
End With

Set myChtRange = Range("S10:W23")
' What range contains data for chart
Set myDataRange = ActiveSheet.ListObjects("Table17").ListColumns(5).Range
' Cover chart range with chart
Set objChart = .ChartObjects.Add( _
    Left:=myChtRange.Left, Top:=myChtRange.Top, _
    Width:=myChtRange.Width, Height:=myChtRange.Height)
' Put all the right stuff in the chart
With objChart.Chart
    .ChartArea.AutoScaleFont = False
    .ChartType = xlLine
    .ChartStyle = 245
    .SetSourceData Source:=myDataRange
    .HasTitle = True
    .HasLegend = False
    .ChartTitle.Characters.Text = "Invoices By Year"
    .ChartTitle.Font.Bold = True
    .ChartTitle.Font.Size = 12
    With .Axes(xlCategory, xlPrimary)
        .HasTitle = True
        With .AxisTitle
            .Characters.Text = "Years"
            .Font.Size = 10
            .Font.Bold = True
        End With
    End With
    With .Axes(xlValue, xlPrimary)
        .HasTitle = True
        .DisplayUnit = xlMillions
        .HasDisplayUnitLabel = False
        With .AxisTitle
            .Characters.Text = "Millions"
            .Font.Size = 10
            .Font.Bold = True
        End With
    End With
End With

Set myChtRange = Range("Y10:AC23")
' What range contains data for chart
Set myDataRange = ActiveSheet.ListObjects("Table30").ListColumns(5).Range
' Cover chart range with chart
Set objChart = .ChartObjects.Add( _
    Left:=myChtRange.Left, Top:=myChtRange.Top, _
    Width:=myChtRange.Width, Height:=myChtRange.Height)
' Put all the right stuff in the chart
With objChart.Chart
    .ChartArea.AutoScaleFont = False
    .ChartType = xlLine
    .ChartStyle = 245
    .SetSourceData Source:=myDataRange
    .HasTitle = True
    .HasLegend = False
    .ChartTitle.Characters.Text = "Req to PO"
    .ChartTitle.Font.Bold = True
    .ChartTitle.Font.Size = 12
    With .Axes(xlCategory, xlPrimary)
        .HasTitle = True
        With .AxisTitle
            .Characters.Text = "Time"
            .Font.Size = 10
            .Font.Bold = True
        End With
    End With
    With .Axes(xlValue, xlPrimary)
        .HasTitle = True
        .DisplayUnit = xlMillions
        .HasDisplayUnitLabel = False
        With .AxisTitle
            .Characters.Text = "Days"
            .Font.Size = 10
            .Font.Bold = True
        End With
    End With
End With
End With
End Sub
</code></pre>

<p>The Table I'm referencing for the first chart looks like this:</p>

<p><a href="https://i.stack.imgur.com/0qBOD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0qBOD.png" alt="Table Example"></a></p>

<p>And the resulting Charts look like this:
<a href="https://i.stack.imgur.com/lx66a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lx66a.png" alt="enter image description here"></a></p>

<p>The issue is I cannot determine how to get the years to show on the horizontal axis instead of Points 1,2,3,4....</p>

<p>Do I need to reference the entire table as I have done for table 2, or do I need to reference just the 5th column as I have done for Table 17?</p>

<p>Macro recorder doesn't show the steps to go from the pictured chart to a chart with the years on the horizontal axis.</p>