ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop through charts (https://www.excelbanter.com/excel-programming/410266-loop-through-charts.html)

Sandy

Loop through charts
 
I have a situation where I would like to loop through all the charts on a
sheet and if a condition is true, hide them.
Can't get it right though!

My attempt - in Sheet_Activate

Dim ch as Chart
If Range("D9").value=0 then
For each ch In Sheets("MySheet")
ch.Visible=False
Next
Else
......................
End If

Sandy


Chip Pearson

Loop through charts
 
Sandy,

Charts that reside on a worksheet (rather than being Chart Sheets) are
wrapped on in a ChartObject object. One child of the ChartObject object is
the Chart object. Try something like:

Dim ChtObj As ChartObject
For Each ChtObj In Worksheets(1).ChartObjects
Debug.Print ChtObj.Name, ChtObj.Chart.Name
Next ChtObj


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



"Sandy" wrote in message
...
I have a situation where I would like to loop through all the charts on a
sheet and if a condition is true, hide them.
Can't get it right though!

My attempt - in Sheet_Activate

Dim ch as Chart
If Range("D9").value=0 then
For each ch In Sheets("MySheet")
ch.Visible=False
Next
Else
......................
End If

Sandy



Sandy

Loop through charts
 
Thank you very much Chip - Perfect
Sandy

"Chip Pearson" wrote in message
...
Sandy,

Charts that reside on a worksheet (rather than being Chart Sheets) are
wrapped on in a ChartObject object. One child of the ChartObject object is
the Chart object. Try something like:

Dim ChtObj As ChartObject
For Each ChtObj In Worksheets(1).ChartObjects
Debug.Print ChtObj.Name, ChtObj.Chart.Name
Next ChtObj


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



"Sandy" wrote in message
...
I have a situation where I would like to loop through all the charts on a
sheet and if a condition is true, hide them.
Can't get it right though!

My attempt - in Sheet_Activate

Dim ch as Chart
If Range("D9").value=0 then
For each ch In Sheets("MySheet")
ch.Visible=False
Next
Else
......................
End If

Sandy




All times are GMT +1. The time now is 03:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com