I have the code and i am trying to fix the axis of the graph, but not getting the success.
I am getting error on this line as method 'mimmum scale' of object 'Axis' failed any way out to fix the same
I am getting error on this line as method 'mimmum scale' of object 'Axis' failed any way out to fix the same
VBA Code:
.MinimumScale = 0 ' Set the minimum scale to 0
VBA Code:
Sub ChangeChartDataRange()
Dim ws As Worksheet
Dim cht As ChartObject
Dim newRange As Range
Dim chartDataRange As String
Dim lastRow As Long
Set ws = ThisWorkbook.Sheets("Utilization Criteria P0")
Set cht = ws.ChartObjects("UCPO")
' Calculate the last row with data in the specified range (columns AD to AK)
lastRow = ws.Cells(ws.Rows.Count, "AD").End(xlUp).Row
' Define the new data range based on the last row with data
Set newRange = ws.Range("AD1:AK" & lastRow)
' Update the chart data range
chartDataRange = "='" & ws.Name & "'!" & newRange.Address
cht.Chart.SetSourceData Source:=Range(chartDataRange)
' Set the XValues property of the chart to the range of horizontal axis values
cht.Chart.SeriesCollection(1).XValues = ws.Range("AD1:AD" & lastRow)
' Manually set the minimum and maximum bounds for the horizontal axis
With cht.Chart.Axes(xlCategory)
.MinimumScale = 0 ' Set the minimum scale to 0 '
.MaximumScale = 100 ' Set the maximum scale to 100
End With
' Refresh the chart
cht.Chart.Refresh
End Sub