Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / January 2008

Tip: Looking for answers? Try searching our database.

VBA: How to loop through a selection of charts?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
spectrallypure - 17 Jan 2008 18:35 GMT
Hi all! I have the following little code that processes the series in
the active chart:

Sub RemoveOldSeriesInActiveChart()
   ActiveChart.SeriesCollection(12).Delete
   ActiveChart.SeriesCollection(11).Delete
  '(...lots of other similar operations...)
End Sub

The problem is that (obviously) it only works on a single chart. I
need to extend the code to perform those operations not only on the
active chart but on all and each of the selected charts (the charts
would be selected using the mouse and holding down the CTRL key).

Unluckily enough, I haven't been able to find a way of looping through
all the charts in a selection of charts. Could somebody please give a
hint of how to accomplish this? Thanks in advance for any help! :)

Regards,

Jorge Luis.
Bob Phillips - 17 Jan 2008 19:33 GMT
For Each chrt In ActiveSheet.ChartObjects
       chrt.Chart.SeriesCollection(12).Delete
       chrt.Chart.SeriesCollection(11).Delete
   Next chrt

Signature

---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

> Hi all! I have the following little code that processes the series in
> the active chart:
[quoted text clipped - 17 lines]
>
> Jorge Luis.
John Bundy - 17 Jan 2008 19:44 GMT
Try putting your code in here, this will loop through all selected charts.
If (ActiveChart Is Nothing) Then
For Each coChartObject In Selection
'code
Next coChartObject
Else
'else code
End If
Signature

-John
Please rate when your question is answered to help us and others know what
is helpful.

> Hi all! I have the following little code that processes the series in
> the active chart:
[quoted text clipped - 17 lines]
>
> Jorge Luis.
spectrallypure - 17 Jan 2008 20:48 GMT
Thanks so much for the replies!

Bob: unfortunately I need to perform the actions only on the selected
charts, not every chart in the current sheet.

John: oddly enough, the given code doesn't seem to work in Excel
2007!!! ...I found the case of a person with the very same problem:
http://www.pcreview.co.uk/forums/thread-3198875.php

...any further ideas?

Regards,

Jorge Luis.
John Bundy - 17 Jan 2008 21:27 GMT
Send me a copy of excel 2007 so i can figure it out? ;)
Signature

-John
Please rate when your question is answered to help us and others know what
is helpful.

> Thanks so much for the replies!
>
[quoted text clipped - 10 lines]
>
> Jorge Luis.
Bob Phillips - 17 Jan 2008 22:01 GMT
For Each chrt In Selection
       chrt.Chart.SeriesCollection(10).Delete
       chrt.Chart.SeriesCollection(11).Delete
   Next chrt

Signature

---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

> Thanks so much for the replies!
>
[quoted text clipped - 10 lines]
>
> Jorge Luis.
spectrallypure - 17 Jan 2008 22:26 GMT
>     For Each chrt In Selection
>         chrt.Chart.SeriesCollection(10).Delete
>         chrt.Chart.SeriesCollection(11).Delete
>     Next chrt

I thought so, but execution fails with "Run-time error 1004: - Invalid
parameter"... seems we're getting closer though...

Maybe it has to do to the fact that the ".Delete" is a method rather
than a property? How can I determine which type of object will "chrt"
be in the above code? ...I remember to have read somewhere that this
information (i.e. the type of a particular element in a VBA code) can
be obtained, but I don't recall where nor how...

Thanks in advance for any further ideas!

Regards,

Jorge.
spectrallypure - 19 Jan 2008 18:34 GMT
spectrallypure - 19 Jan 2008 22:12 GMT
spectrallypure - 21 Jan 2008 04:22 GMT
spectrallypure - 22 Jan 2008 17:29 GMT
spectrallypure - 27 Jan 2008 00:43 GMT
Hello all!

I still haven't figured this one out... I would be really grateful is
someone could throw any ideas over this issue. Thanks in advance for
any help.

Regards,

Jorge Luis.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.