how can i deal with a macro that copy's a sheet the charts all end up with different names?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,187
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone ,

I really stuck, just when I though I was making progress,
I have a macro that copys a sheet and then does a few things to the copied sheet
Code:
Sub Macro2()
   ActiveSheet.Unprotect
    Application.ScreenUpdating = False
    Sheets("Master Dashboard").Select
    Sheets("Master Dashboard").Copy After:=Sheets(5)
    ActiveSheet.Name = Range("AC7").Value
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.Axes(xlValue).Select
    ActiveChart.Axes(xlValue).MinimumScale = Range("EU2")
    ActiveChart.Axes(xlValue).MaximumScale = Range("EV2")



Sheets("Master Dashboard").Select
     Columns("C:Z").Hidden = True
    Columns("AE:AX").Hidden = True
  Range("AC7:AD7").ClearContents
 ActiveSheet.Protect
Application.ScreenUpdating = True
End Sub
The problem is this part
ActiveSheet.ChartObjects("Chart 1").Activate
When I copy the sheet it automaticly give the charts a new name on the new sheet, so whilst it Chart 1 in Master Dashboard tab it becomes Chart ???? in the new tab,

How can I deal with this?
is there a method of renaming the chart? i could add so the chart is given a name by the macro?
Please help if you can
Tony
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi
Try this:

Code:
Sub Macro2()
Dim i%
ActiveSheet.Unprotect
Application.ScreenUpdating = False
Sheets("Master Dashboard").Activate
Sheets("Master Dashboard").Copy After:=Sheets(5)
ActiveSheet.Name = ActiveSheet.Range("AC7").Value
For i = 1 To ActiveSheet.ChartObjects.Count
    ActiveSheet.ChartObjects(i).Name = "Chart " & i ' rename
Next
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Axes(xlValue).MinimumScale = Range("EU2")
ActiveChart.Axes(xlValue).MaximumScale = Range("EV2")
Sheets("Master Dashboard").Activate
Columns("C:Z").Hidden = True
Columns("AE:AX").Hidden = True
Range("AC7:AD7").ClearContents
ActiveSheet.Protect
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,206,943
Messages
6,075,776
Members
446,154
Latest member
Dirk46

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