Excel 2016 error91 setting xlPrimary axis and xlSecondaryaxis to none

bastian18

New Member
Joined
Aug 15, 2018
Messages
22
Hello
I have a Chart in a Worksheet. In the Chart, I am trying to set xlPrimary axis and xlSecondaryaxis to none.
I opened the workbook in Excel and made the changes manually with the Recorder on.
This is the recorded macro code:
Code:
ActiveChart.Axes(xlValue, xlSecondary).Select
Selection.TickLabelPosition = xlNone

However, when I run the macro code VBA displays error91 in this line:
Code:
ActiveChart.Axes(xlValue, xlSecondary).Selec
VBA Run-time Error '91':confused:
Object-variable or With block variable are not set


Then I tried this code:
Code:
Dim ws As WorksheetDim ch As Chart


Set ch = ActiveChart
	With ch.Axes(xlValue, xlSecondary).Select
		Selection.TickLabelPosition = xlNone
	End With
Again VBA displays the same error:oops: in this line:
Code:
 With ch.Axes(xlValue, xlSecondary).Select

Please, could anyone to help me to fix this error

Thanks in advance
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Upvote 0
Joe4
Your recommendation works fine:). Now, this is my code

Dim wb As Workbook
Dim ws As Worksheet
Dim mychart As ChartObject
Set wb = ThisWorkbook
Set ws = wb.Sheets("SheetName")
Set mychart = ws.ChartObjects("Chart 1")
With mychart.Chart
.Axes(xlValue, xlPrimary).TickLabelPosition = xlNone
.Axes(xlValue, xlSecondary).TickLabelPosition = xlNone
End With

My headache is gone
Thank you very much indeed
 
Upvote 0
You are welcome.
Glad I was able to help! :)
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,891
Members
449,194
Latest member
JayEggleton

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