Graph Axis

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,134
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
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
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
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi vmjam02. There doesn't seem to be anything wrong with your code syntax which makes me think that maybe the series doesn't exist. Trial setting your source data with this instead of inserting a formula. HTH. Dave
VBA Code:
cht.Chart.SetSourceData Source:=newRange, PlotBy:=xlColumns
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top