Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tom tom is offline
external usenet poster
 
Posts: 570
Default For each chart loop not working

I am trying to modify a bunch of charts using a For each loop. However when I
check to count the number of charts I get 0. Here is my code:


MsgBox ActiveWorkbook.Charts.Count (this message show 0 charts)
' however this following message indicates the workbook contains a chart
named Chart 85

MsgBox ActiveWorkbook.Charts.Name (this message show "Chart 85")

So since there are 0 charts the for loop does not work


For Each mychart In ActiveWorkbook.Charts


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default For each chart loop not working

I believe you have to use ChartObjects if the charts are embedded on your
worksheets. If they have their own page the you can just use Charts. See
VBA help for details.

"Tom" wrote:

I am trying to modify a bunch of charts using a For each loop. However when I
check to count the number of charts I get 0. Here is my code:


MsgBox ActiveWorkbook.Charts.Count (this message show 0 charts)
' however this following message indicates the workbook contains a chart
named Chart 85

MsgBox ActiveWorkbook.Charts.Name (this message show "Chart 85")

So since there are 0 charts the for loop does not work


For Each mychart In ActiveWorkbook.Charts


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default For each chart loop not working

Tom,

If the charts are in a worksheet, not on their own chart sheet, you have to
use the ChartObjects instead of charts. However, each ChartObject has it's
own chart object, which you use to access some of the charts properties.
For example, this

This code will cycle through each worksheet and tell you the some info about
the charts. You can see that some of the info, like Count and location, is
in ChartObject, some is in ChartObject.Chart.

Sub test()
Dim ws As Worksheet
Dim coChart As ChartObject

For Each ws In ActiveWorkbook.Worksheets
Debug.Print ws.Name & " has " & ws.ChartObjects.Count & " charts"
For Each coChart In ws.ChartObjects
Debug.Print " " & coChart.Name
Debug.Print " is located at " & coChart.TopLeftCell.Address
If coChart.Chart.HasTitle Then
Debug.Print " title is " & coChart.Chart.ChartTitle.Text
Else
Debug.Print " no title"
End If
Next coChart
Next ws
End Sub


"Tom" wrote in message
...
I am trying to modify a bunch of charts using a For each loop. However when
I
check to count the number of charts I get 0. Here is my code:


MsgBox ActiveWorkbook.Charts.Count (this message show 0 charts)
' however this following message indicates the workbook contains a chart
named Chart 85

MsgBox ActiveWorkbook.Charts.Name (this message show "Chart 85")

So since there are 0 charts the for loop does not work


For Each mychart In ActiveWorkbook.Charts




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
Do Until Loop Not Working PJFry Excel Programming 3 October 1st 07 07:20 PM
Do Until Loop Not Working PJFry Excel Programming 1 October 1st 07 07:20 PM
Loop Not Working Paul Black Excel Programming 7 August 29th 07 08:33 PM
Loop not working!! Simon Excel Programming 2 August 2nd 05 04:16 PM
Do...Loop not working Sunny Lin Excel Programming 1 April 14th 05 01:19 AM


All times are GMT +1. The time now is 12:03 PM.

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

About Us

"It's about Microsoft Excel"