VBA formats just first of several embedded charts

Ummm1

New Member
Joined
May 1, 2014
Messages
12
Hi, I am trying to loop through all nine charts on a worksheet to change the formatting. I think these charts are called "embedded", since there is other stuff on the sheet: formulas and text. The looping code I wrote operated on just the first chart. To try to find the problem I've reduced the code (without the loop) to this:

Sub formatcharts()
Worksheets("treecounts").ChartObjects(1).Chart.ChartArea.Format.Line.Visible = True
End Sub

This works for the first chart. But when I replace that (1) with (2), nothing happens to any of the nine charts.

I guess this is something very simple, but so far I can't find what the problem is. I hope someone can help; thanks!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
If your worksheet called "treecounts" contains more than one embedded chart, and you change the 1 to a 2, and then you run that code, it should successfully make the border/line for the second embedded chart visible, if it's not already visible.

If you're still having problems, I would suggest posting your complete code, and someone here will very likely be able to help.
 
Upvote 0
Hi, just wanted put put in my solution here with hope it might help someone else. My coding was fine; the problem was that for some reason, on the original charts the border and axes lines that I was trying to format had the color set to "Automatic" for all but the first chart. Automatic resulted in a grey color that I didn't see. I had apparently manually changed the color to black for the first chart. So while it appeared that the other eight charts weren't formatting, they were--but in a color I didn't see. (Color was not one of the formats I was trying to change.)
 
Upvote 0
That's great, I'm glad you were able to solve your problem. Thanks for sharing it.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,821
Members
449,049
Latest member
cybersurfer5000

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