Run time error 1004 with vba ticklabels.offset

mhwolog

New Member
Joined
Sep 28, 2016
Messages
28
Hello,
I'm trying to use VBA to alter the parameters of my chart. But specifically with the Ticklabels.Offset - I get "Run time error 1004 - Parameter not valid", and I can't work out why.

The code below works for the maximum scale and minimum scale, then gets an error where labelled.

Code:
ActiveSheet.ChartObjects("Chart 2").Activate
  With ActiveChart.Axes(xlValue, xlPrimary) 'y-axis of chart
    .MaximumScale = ActiveSheet.Range("AC63").Value
    .MinimumScale = ActiveSheet.Range("AE63").Value
        
  End With


With ActiveChart.Axes(xlCategory).TickLabels
 .Offset = -(ActiveSheet.Range("AE63").Value) / 7  ' error here
End With


I have also tried recording the macro, but when I run it again I get the error on the 5th line

Code:
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveChart.PlotArea.Select
    ActiveChart.Axes(xlCategory).MajorGridlines.Select
    ActiveChart.Axes(xlCategory).Select
    ActiveChart.Axes(xlCategory).TickLabels.Offset = 5000 'error here
    Application.CommandBars("Format Object").Visible = False

Thanks for your help
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Select the chart and run this code:
Code:
Sub trychart()
    Dim i As Long
    On Error Resume Next
    Do While Err = 0
        i = i + 1
        ActiveChart.Axes(xlCategory).TickLabels.Offset = i
    Loop
    Debug.Print "i=" & i, Err.Number, Err.Description


End Sub
it will show you that .TickLabels.Offset does not accept values greater than 1000.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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