Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Macro to change chart name only once

I have a sheet with 3 charts, two of them are called "Chart 2" and I need to
perform via macro a change on the axis.

If I do not rename one of them the macro performs only once. If I rename it
does it fine, but if I run the macro twice it get stuck.

That is what I did so far:


ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.ChartObjects("Chart 2").Name = "Chart 1"
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True

Please help!

--
Aligi
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,355
Default Macro to change chart name only once

How about something like this

Sub Test()
Dim aWS As Worksheet
Dim ChtObj As ChartObject

Set aWS = ActiveSheet

For Each ChtObj In aWS.ChartObjects
Debug.Print ChtObj.Name, ChtObj.Chart.Axes(xlValue).MinimumScaleIsAuto
ChtObj.Chart.Axes(xlValue).MinimumScaleIsAuto = False
Debug.Print ChtObj.Name, ChtObj.Chart.Axes(xlValue).MinimumScaleIsAuto

Next ChtObj

End Sub

Here, I don't believe you'd need to change the chart name either.

Notice that I didn't use SELECT once in this code.
--
HTH,
Barb Reinhardt



"Aligi" wrote:

I have a sheet with 3 charts, two of them are called "Chart 2" and I need to
perform via macro a change on the axis.

If I do not rename one of them the macro performs only once. If I rename it
does it fine, but if I run the macro twice it get stuck.

That is what I did so far:


ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.ChartObjects("Chart 2").Name = "Chart 1"
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True

Please help!

--
Aligi

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Macro to change chart name only once

Hi Barb,

Brilliat!! Did work perfect... mind the value was TRUE but I thought you
were testing if I am still awake :o)

Thank you very much.

--
Aligi


"Barb Reinhardt" wrote:

How about something like this

Sub Test()
Dim aWS As Worksheet
Dim ChtObj As ChartObject

Set aWS = ActiveSheet

For Each ChtObj In aWS.ChartObjects
Debug.Print ChtObj.Name, ChtObj.Chart.Axes(xlValue).MinimumScaleIsAuto
ChtObj.Chart.Axes(xlValue).MinimumScaleIsAuto = False
Debug.Print ChtObj.Name, ChtObj.Chart.Axes(xlValue).MinimumScaleIsAuto

Next ChtObj

End Sub

Here, I don't believe you'd need to change the chart name either.

Notice that I didn't use SELECT once in this code.
--
HTH,
Barb Reinhardt



"Aligi" wrote:

I have a sheet with 3 charts, two of them are called "Chart 2" and I need to
perform via macro a change on the axis.

If I do not rename one of them the macro performs only once. If I rename it
does it fine, but if I run the macro twice it get stuck.

That is what I did so far:


ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.ChartObjects("Chart 2").Name = "Chart 1"
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True

Please help!

--
Aligi

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro to change chart name only once

Maybe you could refer to the charts by their numbers:

ActiveSheet.ChartObjects(1).Activate

Or rename the chartobjects before you start your macro and then don't rename
them in your code?

If you ctrl-click on the chart's border, you should see the chart name in the
namebox (to the left of the formula bar). Just type the new name (make it a
nice unique name!) and then hit enter to complete the rename.



Aligi wrote:

I have a sheet with 3 charts, two of them are called "Chart 2" and I need to
perform via macro a change on the axis.

If I do not rename one of them the macro performs only once. If I rename it
does it fine, but if I run the macro twice it get stuck.

That is what I did so far:

ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.ChartObjects("Chart 2").Name = "Chart 1"
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True

Please help!

--
Aligi


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,355
Default Macro to change chart name only once

I didn't intend to do that, but I guess you figured it out yourself.

Barb Reinhardt



"Aligi" wrote:

Hi Barb,

Brilliat!! Did work perfect... mind the value was TRUE but I thought you
were testing if I am still awake :o)

Thank you very much.

--
Aligi


"Barb Reinhardt" wrote:

How about something like this

Sub Test()
Dim aWS As Worksheet
Dim ChtObj As ChartObject

Set aWS = ActiveSheet

For Each ChtObj In aWS.ChartObjects
Debug.Print ChtObj.Name, ChtObj.Chart.Axes(xlValue).MinimumScaleIsAuto
ChtObj.Chart.Axes(xlValue).MinimumScaleIsAuto = False
Debug.Print ChtObj.Name, ChtObj.Chart.Axes(xlValue).MinimumScaleIsAuto

Next ChtObj

End Sub

Here, I don't believe you'd need to change the chart name either.

Notice that I didn't use SELECT once in this code.
--
HTH,
Barb Reinhardt



"Aligi" wrote:

I have a sheet with 3 charts, two of them are called "Chart 2" and I need to
perform via macro a change on the axis.

If I do not rename one of them the macro performs only once. If I rename it
does it fine, but if I run the macro twice it get stuck.

That is what I did so far:


ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.ChartObjects("Chart 2").Name = "Chart 1"
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True

Please help!

--
Aligi

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to change chart name only once Aligi Excel Discussion (Misc queries) 0 August 3rd 08 05:39 PM
Pivot chart, macro to change color Daniel Charts and Charting in Excel 3 July 14th 07 04:34 PM
Excel bar chart formatting of bars to change colors as data change JudyT Excel Discussion (Misc queries) 1 January 24th 07 06:07 PM
chart MAcro to change on activecell flow23 Excel Discussion (Misc queries) 0 December 7th 05 04:46 PM
Macro to change Chart Range when inserting a column Mark Charts and Charting in Excel 1 September 13th 05 01:12 PM


All times are GMT +1. The time now is 01:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"