Q:

Excel VBA - Error in Updating Maximum Scale for XY Scatter Chart

I have a code where it need to change the scale of chart when user click a button. However the code is not working for the maximum scale which is the last used row. Below is the code:
Option Explicit

Sub ScaleAxes()

Dim LastRow, LastRow2 As Long
Dim ws As Worksheet

Set ws = ActiveChart.Parent.Parent

With ActiveChart.Axes(xlCategory, xlPrimary)
    LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    .MaximumScale = LastRow
    .MinimumScale = ActiveSheet.Range("A2").Value
End With

End Sub

In the picture below is the generated graph from my data which is Power vs Frequency. The Frequency range is 1.12 GHz to 1.45 GHz. 

After i apply the code above, the chart changed as below:

As you can see in the picture, the minimum scale which is 1.12 GHz is working but not for the maximum scale. Are there anything wrong with the code?
Thank you very much.

A:

The problem is that LastRow is the number of the last row. I assume you wanted the value of the last cell. 
.MaximumScale = ws.Cells(LastRow, 1).Value

