Chart Axis Modification

  • Thread starter Thread starter R Tanner
  • Start date Start date
R

R Tanner

Hi,

I have been trying to write a procedure that modifies the primary
horizontal axis. Here is the code:

Set Charts("Main").Axes(xlCategory).CategoryNames = _
Worksheets("Sheet1").Range("D84:I84")

When I try to run it, I get 'Subscript out of Range'

Does anyone know what I'm doing wrong?
 
Try this and report back which line errors and the error description

Sub test()
Dim rng As Range
Dim cht As Chart
Dim ax As Axis

Set rng = Worksheets("Sheet1").Range("D84:I84")

Set cht = Charts("Main")

Set ax = cht.Axes(xlCategory)

ax.CategoryNames = rng

End Sub

Regards,
Peter T
 
Try this and report back which line errors and the error description

Sub test()
Dim rng As Range
Dim cht As Chart
Dim ax As Axis

Set rng = Worksheets("Sheet1").Range("D84:I84")

Set cht = Charts("Main")

Set ax = cht.Axes(xlCategory)

ax.CategoryNames = rng

End Sub

Regards,
Peter T

I'm getting the same error message 'Subcript out of range'.

When I go to the selection pane, the name of the chart is 'Chart 1'.
This is what I would use in my code, is it not?

Thanks
 
Try this and report back which line errors and the error description

Sub test()
Dim rng As Range
Dim cht As Chart
Dim ax As Axis

Set rng = Worksheets("Sheet1").Range("D84:I84")

Set cht = Charts("Main")

Set ax = cht.Axes(xlCategory)

ax.CategoryNames = rng

End Sub

Regards,
Peter T

I get error 9, and from what I understand, that relates to variable
declaration. we have declared all variables in the procedure
however. The help menu discusses issues with identifying the array.
I'm not sure...
 
Is your chart a chart-sheet or is it an embedded chart on a sheet. If it's a
chart-sheet, which is what your original code suggests, in this line

Set cht = Charts("Main")

ensure "Main" is the name of the chart-sheet or change as necessary

But you say -
When I go to the selection pane, the name of the chart is 'Chart 1'.
This is what I would use in my code, is it not?

I don't know what you mean by "selection pane" but what this suggests your
chart is an embedded chart. If so start off like this -

Set cht = Sheets("sheet-Name").ChartObjects("Chart 1").Chart

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top