Cannot activate a chart on a sheet

F

Farooq Sheri

I have a embedded chart (there is only one chart) on a sheet. I tried naming
it with

ActivesSheet.ChartObjects(1).Name = "chart 1"

Question 1: did the above statement name the chart object or the chart
contained within the chart object?

Using a macro I tried to activate the chart with the command

Worksheets(2).ChartObjects(1).Activate

this however did not activate the chart.

If however I change the command to

Worksheets(2).ChartObjects("Chart 75").Activate

the chart is activated ("Chart 75" is the name of the chart as it appears on
the top of the widow that pops up if you right click on the chart and select
Chart Window). This name (on the Chart Window) changes everytime the chart is
redrawn.

Question 2: How can I select the chart on the desired sheet?
Question 3: Can I somehow extract the name as it appears on the Chart Window?

I do not know if it has anything to do with it, but the chart on sheet 2 was
placed as a result of a comboBox_Change code. ComboBox is on sheet 1.

Thanks for your help.
 
P

Peter T

Comments in line -

Farooq Sheri said:
I have a embedded chart (there is only one chart) on a sheet. I tried naming
it with

ActivesSheet.ChartObjects(1).Name = "chart 1"

Question 1: did the above statement name the chart object or the chart
contained within the chart object?

It should do if you amend the typo ActivesSheet to ActiveSheet and no other
chart on the sheet with that name (subject protection).
Using a macro I tried to activate the chart with the command

Worksheets(2).ChartObjects(1).Activate

this however did not activate the chart.

If however I change the command to

Worksheets(2).ChartObjects("Chart 75").Activate

the chart is activated ("Chart 75" is the name of the chart as it appears on
the top of the widow that pops up if you right click on the chart and select
Chart Window).

Not sure why ChartObjects(1) fails but ChartObjects("Chart 75") works,
there's obviously at least one chartobject on the sheet.
This name (on the Chart Window) changes everytime the chart is
redrawn.

You mean each time you deleate & recreate a chart. The number will increment
to the total number of objects that have 'ever' been added to the sheet. The
counter is only reset if the wb & sheet is saved with no objects.
Question 2: How can I select the chart on the desired sheet?

Need to activate the sheet first.
Question 3: Can I somehow extract the name as it appears on the Chart
Window?

Activesheet.Chartobjects.Chart.Name returns 'sheetname chartname' which will
be prefixed with the sheetname (the chartwindow also includes [wb-name]).
It's actual name though for referencing purposes is -
Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name
I do not know if it has anything to do with it, but the chart on sheet 2 was
placed as a result of a comboBox_Change code. ComboBox is on sheet 1.

Not directly related

Regards,
Peter T
 
F

Farooq Sheri

Thanks Peter for the detailed reply. There is no typo with the command
ActiveSheet.ChartObjects(1).Name = "chart 1" within my code.

At any given time there is only one chart on the sheet so it really beats me
why the command Worksheets(2).ChartObjects(1).Activate would not activate
the chart (the sheet is already activated).

Although I am still struggling with it but thank you for your reply. I will
try using the chart name as suggested by you
(Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name) and see if I
can get the chart activated.

Regards
Farooq

Peter T said:
Comments in line -

Farooq Sheri said:
I have a embedded chart (there is only one chart) on a sheet. I tried naming
it with

ActivesSheet.ChartObjects(1).Name = "chart 1"

Question 1: did the above statement name the chart object or the chart
contained within the chart object?

It should do if you amend the typo ActivesSheet to ActiveSheet and no other
chart on the sheet with that name (subject protection).
Using a macro I tried to activate the chart with the command

Worksheets(2).ChartObjects(1).Activate

this however did not activate the chart.

If however I change the command to

Worksheets(2).ChartObjects("Chart 75").Activate

the chart is activated ("Chart 75" is the name of the chart as it appears on
the top of the widow that pops up if you right click on the chart and select
Chart Window).

Not sure why ChartObjects(1) fails but ChartObjects("Chart 75") works,
there's obviously at least one chartobject on the sheet.
This name (on the Chart Window) changes everytime the chart is
redrawn.

You mean each time you deleate & recreate a chart. The number will increment
to the total number of objects that have 'ever' been added to the sheet. The
counter is only reset if the wb & sheet is saved with no objects.
Question 2: How can I select the chart on the desired sheet?

Need to activate the sheet first.
Question 3: Can I somehow extract the name as it appears on the Chart
Window?

Activesheet.Chartobjects.Chart.Name returns 'sheetname chartname' which will
be prefixed with the sheetname (the chartwindow also includes [wb-name]).
It's actual name though for referencing purposes is -
Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name
I do not know if it has anything to do with it, but the chart on sheet 2 was
placed as a result of a comboBox_Change code. ComboBox is on sheet 1.

Not directly related

Regards,
Peter T
 
P

Peter T

Sometimes it's necessary to deselect some other chart first, particularly if
it's in a window. Also sometimes necessary to select the .Chart if it was
selected as a chartobject. But if the current selection is say a cell I have
no idea why referring to it by it's index number fails but works with it's
name.

Are you absolutely sure there's only one chartobject, eg you didn't once
assume deleting all the rows it's in would delete it.
In the immediate window (ctrl-g) type
?activesheet.chartobjects.count
and press enter

Regards,
Peter T

Farooq Sheri said:
Thanks Peter for the detailed reply. There is no typo with the command
ActiveSheet.ChartObjects(1).Name = "chart 1" within my code.

At any given time there is only one chart on the sheet so it really beats me
why the command Worksheets(2).ChartObjects(1).Activate would not activate
the chart (the sheet is already activated).

Although I am still struggling with it but thank you for your reply. I will
try using the chart name as suggested by you
(Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name) and see if I
can get the chart activated.

Regards
Farooq

Peter T said:
Comments in line -

Farooq Sheri said:
I have a embedded chart (there is only one chart) on a sheet. I tried naming
it with

ActivesSheet.ChartObjects(1).Name = "chart 1"

Question 1: did the above statement name the chart object or the chart
contained within the chart object?

It should do if you amend the typo ActivesSheet to ActiveSheet and no other
chart on the sheet with that name (subject protection).
Using a macro I tried to activate the chart with the command

Worksheets(2).ChartObjects(1).Activate

this however did not activate the chart.

If however I change the command to

Worksheets(2).ChartObjects("Chart 75").Activate

the chart is activated ("Chart 75" is the name of the chart as it
appears
on
the top of the widow that pops up if you right click on the chart and select
Chart Window).

Not sure why ChartObjects(1) fails but ChartObjects("Chart 75") works,
there's obviously at least one chartobject on the sheet.
This name (on the Chart Window) changes everytime the chart is
redrawn.

You mean each time you deleate & recreate a chart. The number will increment
to the total number of objects that have 'ever' been added to the sheet. The
counter is only reset if the wb & sheet is saved with no objects.
Question 2: How can I select the chart on the desired sheet?

Need to activate the sheet first.
Question 3: Can I somehow extract the name as it appears on the Chart
Window?

Activesheet.Chartobjects.Chart.Name returns 'sheetname chartname' which will
be prefixed with the sheetname (the chartwindow also includes [wb-name]).
It's actual name though for referencing purposes is -
Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name
I do not know if it has anything to do with it, but the chart on sheet
2
was
placed as a result of a comboBox_Change code. ComboBox is on sheet 1.

Not directly related

Regards,
Peter T
 
F

Farooq Sheri

Thanks Peter. I used the name as obtained from ActiveChart.Parent.Name to get
the desired results.

Thanks a lot.

Farooq Sheri

Peter T said:
Sometimes it's necessary to deselect some other chart first, particularly if
it's in a window. Also sometimes necessary to select the .Chart if it was
selected as a chartobject. But if the current selection is say a cell I have
no idea why referring to it by it's index number fails but works with it's
name.

Are you absolutely sure there's only one chartobject, eg you didn't once
assume deleting all the rows it's in would delete it.
In the immediate window (ctrl-g) type
?activesheet.chartobjects.count
and press enter

Regards,
Peter T

Farooq Sheri said:
Thanks Peter for the detailed reply. There is no typo with the command
ActiveSheet.ChartObjects(1).Name = "chart 1" within my code.

At any given time there is only one chart on the sheet so it really beats me
why the command Worksheets(2).ChartObjects(1).Activate would not activate
the chart (the sheet is already activated).

Although I am still struggling with it but thank you for your reply. I will
try using the chart name as suggested by you
(Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name) and see if I
can get the chart activated.

Regards
Farooq

Peter T said:
Comments in line -

I have a embedded chart (there is only one chart) on a sheet. I tried
naming
it with

ActivesSheet.ChartObjects(1).Name = "chart 1"

Question 1: did the above statement name the chart object or the chart
contained within the chart object?

It should do if you amend the typo ActivesSheet to ActiveSheet and no other
chart on the sheet with that name (subject protection).

Using a macro I tried to activate the chart with the command

Worksheets(2).ChartObjects(1).Activate

this however did not activate the chart.

If however I change the command to

Worksheets(2).ChartObjects("Chart 75").Activate

the chart is activated ("Chart 75" is the name of the chart as it appears
on
the top of the widow that pops up if you right click on the chart and
select
Chart Window).

Not sure why ChartObjects(1) fails but ChartObjects("Chart 75") works,
there's obviously at least one chartobject on the sheet.

This name (on the Chart Window) changes everytime the chart is
redrawn.

You mean each time you deleate & recreate a chart. The number will increment
to the total number of objects that have 'ever' been added to the sheet. The
counter is only reset if the wb & sheet is saved with no objects.

Question 2: How can I select the chart on the desired sheet?

Need to activate the sheet first.

Question 3: Can I somehow extract the name as it appears on the Chart
Window?

Activesheet.Chartobjects.Chart.Name returns 'sheetname chartname' which will
be prefixed with the sheetname (the chartwindow also includes [wb-name]).
It's actual name though for referencing purposes is -
Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name

I do not know if it has anything to do with it, but the chart on sheet 2
was
placed as a result of a comboBox_Change code. ComboBox is on sheet 1.

Not directly related

Regards,
Peter T
 
P

Peter T

Did you programmatically check how many chartobjects exit on the sheet.

Regards,
Peter T

Farooq Sheri said:
Thanks Peter. I used the name as obtained from ActiveChart.Parent.Name to get
the desired results.

Thanks a lot.

Farooq Sheri

Peter T said:
Sometimes it's necessary to deselect some other chart first, particularly if
it's in a window. Also sometimes necessary to select the .Chart if it was
selected as a chartobject. But if the current selection is say a cell I have
no idea why referring to it by it's index number fails but works with it's
name.

Are you absolutely sure there's only one chartobject, eg you didn't once
assume deleting all the rows it's in would delete it.
In the immediate window (ctrl-g) type
?activesheet.chartobjects.count
and press enter

Regards,
Peter T

Farooq Sheri said:
Thanks Peter for the detailed reply. There is no typo with the command
ActiveSheet.ChartObjects(1).Name = "chart 1" within my code.

At any given time there is only one chart on the sheet so it really
beats
me
why the command Worksheets(2).ChartObjects(1).Activate would not activate
the chart (the sheet is already activated).

Although I am still struggling with it but thank you for your reply. I will
try using the chart name as suggested by you
(Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name) and see if I
can get the chart activated.

Regards
Farooq

:

Comments in line -

I have a embedded chart (there is only one chart) on a sheet. I tried
naming
it with

ActivesSheet.ChartObjects(1).Name = "chart 1"

Question 1: did the above statement name the chart object or the chart
contained within the chart object?

It should do if you amend the typo ActivesSheet to ActiveSheet and
no
other
chart on the sheet with that name (subject protection).

Using a macro I tried to activate the chart with the command

Worksheets(2).ChartObjects(1).Activate

this however did not activate the chart.

If however I change the command to

Worksheets(2).ChartObjects("Chart 75").Activate

the chart is activated ("Chart 75" is the name of the chart as it appears
on
the top of the widow that pops up if you right click on the chart and
select
Chart Window).

Not sure why ChartObjects(1) fails but ChartObjects("Chart 75") works,
there's obviously at least one chartobject on the sheet.

This name (on the Chart Window) changes everytime the chart is
redrawn.

You mean each time you deleate & recreate a chart. The number will increment
to the total number of objects that have 'ever' been added to the
sheet.
The
counter is only reset if the wb & sheet is saved with no objects.

Question 2: How can I select the chart on the desired sheet?

Need to activate the sheet first.

Question 3: Can I somehow extract the name as it appears on the Chart
Window?

Activesheet.Chartobjects.Chart.Name returns 'sheetname chartname'
which
will
be prefixed with the sheetname (the chartwindow also includes [wb-name]).
It's actual name though for referencing purposes is -
Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name

I do not know if it has anything to do with it, but the chart on
sheet
2
was
placed as a result of a comboBox_Change code. ComboBox is on sheet 1.

Not directly related

Regards,
Peter T
 
F

Farooq Sheri

I am quite sure because each time before any data / chart was put on the
sheet cells.delete was used to delete the sheet of any previous data / chart.
I have used the command activesheet.chartobjects(1).activate previously and
it works but for some strange reasons it is not working here. This case is a
good one for head scratching. In fact just to test I copied the data from
this sheet onto another sheet and made a chart and the above command
activated the chart.

Thanks and regards.
Farooq


Peter T said:
Did you programmatically check how many chartobjects exit on the sheet.

Regards,
Peter T

Farooq Sheri said:
Thanks Peter. I used the name as obtained from ActiveChart.Parent.Name to get
the desired results.

Thanks a lot.

Farooq Sheri

Peter T said:
Sometimes it's necessary to deselect some other chart first, particularly if
it's in a window. Also sometimes necessary to select the .Chart if it was
selected as a chartobject. But if the current selection is say a cell I have
no idea why referring to it by it's index number fails but works with it's
name.

Are you absolutely sure there's only one chartobject, eg you didn't once
assume deleting all the rows it's in would delete it.
In the immediate window (ctrl-g) type
?activesheet.chartobjects.count
and press enter

Regards,
Peter T

Thanks Peter for the detailed reply. There is no typo with the command
ActiveSheet.ChartObjects(1).Name = "chart 1" within my code.

At any given time there is only one chart on the sheet so it really beats
me
why the command Worksheets(2).ChartObjects(1).Activate would not activate
the chart (the sheet is already activated).

Although I am still struggling with it but thank you for your reply. I
will
try using the chart name as suggested by you
(Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name) and see if I
can get the chart activated.

Regards
Farooq

:

Comments in line -

I have a embedded chart (there is only one chart) on a sheet. I tried
naming
it with

ActivesSheet.ChartObjects(1).Name = "chart 1"

Question 1: did the above statement name the chart object or the chart
contained within the chart object?

It should do if you amend the typo ActivesSheet to ActiveSheet and no
other
chart on the sheet with that name (subject protection).

Using a macro I tried to activate the chart with the command

Worksheets(2).ChartObjects(1).Activate

this however did not activate the chart.

If however I change the command to

Worksheets(2).ChartObjects("Chart 75").Activate

the chart is activated ("Chart 75" is the name of the chart as it
appears
on
the top of the widow that pops up if you right click on the chart and
select
Chart Window).

Not sure why ChartObjects(1) fails but ChartObjects("Chart 75") works,
there's obviously at least one chartobject on the sheet.

This name (on the Chart Window) changes everytime the chart is
redrawn.

You mean each time you deleate & recreate a chart. The number will
increment
to the total number of objects that have 'ever' been added to the sheet.
The
counter is only reset if the wb & sheet is saved with no objects.

Question 2: How can I select the chart on the desired sheet?

Need to activate the sheet first.

Question 3: Can I somehow extract the name as it appears on the Chart
Window?

Activesheet.Chartobjects.Chart.Name returns 'sheetname chartname' which
will
be prefixed with the sheetname (the chartwindow also includes
[wb-name]).
It's actual name though for referencing purposes is -
Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name

I do not know if it has anything to do with it, but the chart on sheet
2
was
placed as a result of a comboBox_Change code. ComboBox is on sheet 1.

Not directly related

Regards,
Peter T
 
P

Peter T

Sometimes the apparently impossible happens!

I suggested double checking with code to confirm you only have one
chartobject. If you have a (say hidden) chart named "Chart 1" it would
explain both why you cannot select ChartObjects("Chart 75") using the code
ChartObjects(1) and cannot rename it as "Chart 1".

It would only take a few seconds to test and 100% eliminate the impossible
possibility.

Regards,
Peter T

Farooq Sheri said:
I am quite sure because each time before any data / chart was put on the
sheet cells.delete was used to delete the sheet of any previous data / chart.
I have used the command activesheet.chartobjects(1).activate previously and
it works but for some strange reasons it is not working here. This case is a
good one for head scratching. In fact just to test I copied the data from
this sheet onto another sheet and made a chart and the above command
activated the chart.

Thanks and regards.
Farooq


Peter T said:
Did you programmatically check how many chartobjects exit on the sheet.

Regards,
Peter T

Farooq Sheri said:
Thanks Peter. I used the name as obtained from ActiveChart.Parent.Name
to
get
the desired results.

Thanks a lot.

Farooq Sheri

:

Sometimes it's necessary to deselect some other chart first, particularly if
it's in a window. Also sometimes necessary to select the .Chart if
it
was
selected as a chartobject. But if the current selection is say a
cell I
have
no idea why referring to it by it's index number fails but works
with
it's
name.

Are you absolutely sure there's only one chartobject, eg you didn't once
assume deleting all the rows it's in would delete it.
In the immediate window (ctrl-g) type
?activesheet.chartobjects.count
and press enter

Regards,
Peter T

Thanks Peter for the detailed reply. There is no typo with the command
ActiveSheet.ChartObjects(1).Name = "chart 1" within my code.

At any given time there is only one chart on the sheet so it
really
beats
me
why the command Worksheets(2).ChartObjects(1).Activate would not activate
the chart (the sheet is already activated).

Although I am still struggling with it but thank you for your reply. I
will
try using the chart name as suggested by you
(Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name) and
see
if I
can get the chart activated.

Regards
Farooq

:

Comments in line -

I have a embedded chart (there is only one chart) on a sheet.
I
tried
naming
it with

ActivesSheet.ChartObjects(1).Name = "chart 1"

Question 1: did the above statement name the chart object or
the
chart
contained within the chart object?

It should do if you amend the typo ActivesSheet to ActiveSheet
and
no
other
chart on the sheet with that name (subject protection).

Using a macro I tried to activate the chart with the command

Worksheets(2).ChartObjects(1).Activate

this however did not activate the chart.

If however I change the command to

Worksheets(2).ChartObjects("Chart 75").Activate

the chart is activated ("Chart 75" is the name of the chart as it
appears
on
the top of the widow that pops up if you right click on the
chart
and
select
Chart Window).

Not sure why ChartObjects(1) fails but ChartObjects("Chart 75") works,
there's obviously at least one chartobject on the sheet.

This name (on the Chart Window) changes everytime the chart is
redrawn.

You mean each time you deleate & recreate a chart. The number will
increment
to the total number of objects that have 'ever' been added to
the
sheet.
The
counter is only reset if the wb & sheet is saved with no objects.

Question 2: How can I select the chart on the desired sheet?

Need to activate the sheet first.

Question 3: Can I somehow extract the name as it appears on
the
Chart
Window?

Activesheet.Chartobjects.Chart.Name returns 'sheetname
chartname'
which
will
be prefixed with the sheetname (the chartwindow also includes
[wb-name]).
It's actual name though for referencing purposes is -
Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name

I do not know if it has anything to do with it, but the chart
on
sheet
2
was
placed as a result of a comboBox_Change code. ComboBox is on
sheet
1.
Not directly related

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

Top