Paste and Alter Charts in VBA

Bazman76

New Member
Joined
Jul 5, 2011
Messages
9
Hi there,

I want to create and alter several charts

By recording a macro I think I am nearly there.

However this line does not work?

ActiveSheet.ChartObjects("Chart" & i).Activate

Can someone please advise

Sub Macro6()
'
' Macro6 Macro
' Macro recorded 05/07/2011 by HP
'

'
For i = 5 To 10
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
ActiveWindow.Visible = False
Windows("RBS_USD_data2.xls").Activate
'Range("L32").Select
Cells(34, 2).Select
ActiveSheet.Paste
ActiveSheet.ChartObjects("Chart" & i).Activate
ActiveChart.SeriesCollection(1).XValues = "=Sheet2!R839C1:R1548C1"
ActiveChart.SeriesCollection(1).Values = "=Sheet2!R839C2:R1548C2"
ActiveChart.SeriesCollection(2).XValues = "=Sheet2!R839C1:R1548C1"
ActiveChart.SeriesCollection(2).Values = "=Sheet2!R839C9:R1548C9"
Next i
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try with a space

ActiveSheet.ChartObjects("Chart " & i).Activate

I think thats probably it but now it appears I have another problem.

Even though I have been deleting all these new charts I have been creating while testing. It seems that when a new chart is pasted its no longer "Chart 5". How can I find out what a freshly pasted chart is called?
 
Upvote 0
no gives me the error

run-time error '424'

object required

I include the ful macro in case I have incorporated your code incorrectly

Sub Macro6()
'
' Macro6 Macro
' Macro recorded 05/07/2011 by HP
'

'
For i = 5 To 10
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
ActiveWindow.Visible = False
Windows("RBS_USD_data2.xls").Activate
'Range("L32").Select
Cells(34, 2).Select
ActiveSheet.Paste
ActiveSheet.ChartObjects(ChartObjects.Count).Activate
'ActiveSheet.ChartObjects("Chart 5").Activate
'ActiveSheet.ChartObjects("Chart " & i).Activate
ActiveChart.SeriesCollection(1).XValues = "=Sheet2!R839C1:R1548C1"
ActiveChart.SeriesCollection(1).Values = "=Sheet2!R839C2:R1548C2"
ActiveChart.SeriesCollection(2).XValues = "=Sheet2!R839C1:R1548C1"
ActiveChart.SeriesCollection(2).Values = "=Sheet2!R839C9:R1548C9"
Next i
End Sub
 
Upvote 0
Sorry, it should be

Code:
ActiveSheet.ChartObjects(ActiveSheet.ChartObjects.Count).Activate
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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