ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Chart Axis Modification (https://www.excelbanter.com/excel-programming/412967-chart-axis-modification.html)

R Tanner

Chart Axis Modification
 
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?

Peter T

Chart Axis Modification
 
Just remove "Set"

Regards,
Peter T


"R Tanner" wrote in message
...
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?




R Tanner

Chart Axis Modification
 
On Jun 23, 8:03 am, "Peter T" <peter_t@discussions wrote:
Just remove "Set"

Regards,
Peter T

"R Tanner" wrote in message

...

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?


It still gives me the 'Subscript out of Range' error...

Peter T

Chart Axis Modification
 
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

"R Tanner" wrote in message
...
On Jun 23, 8:03 am, "Peter T" <peter_t@discussions wrote:
Just remove "Set"

Regards,
Peter T

"R Tanner" wrote in message


...

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?


It still gives me the 'Subscript out of Range' error...




R Tanner

Chart Axis Modification
 
On Jun 23, 9:45 am, "Peter T" <peter_t@discussions wrote:
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

"R Tanner" wrote in message

... On Jun 23, 8:03 am, "Peter T" <peter_t@discussions wrote:
Just remove "Set"


Regards,
Peter T


"R Tanner" wrote in message


...



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?


It still gives me the 'Subscript out of Range' error...


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

R Tanner

Chart Axis Modification
 
On Jun 23, 9:45 am, "Peter T" <peter_t@discussions wrote:
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

"R Tanner" wrote in message

... On Jun 23, 8:03 am, "Peter T" <peter_t@discussions wrote:
Just remove "Set"


Regards,
Peter T


"R Tanner" wrote in message


...



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?


It still gives me the 'Subscript out of Range' error...


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...

Peter T

Chart Axis Modification
 
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



"R Tanner" wrote in message
...
On Jun 23, 9:45 am, "Peter T" <peter_t@discussions wrote:
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

"R Tanner" wrote in message


...
On Jun 23, 8:03 am, "Peter T" <peter_t@discussions wrote:
Just remove "Set"


Regards,
Peter T


"R Tanner" wrote in message



...



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?


It still gives me the 'Subscript out of Range' error...


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





All times are GMT +1. The time now is 12:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com