Multiple arrays

austin350s10

Active Member
Joined
Jul 30, 2010
Messages
321
How can I adjust the following code so that both arrays will work? Currently this code loops through both arrays completely before finishing. Basically, what I am looking for here is a way to assign a charts title based on the findings of the GraphName array.

So when in position 0 of the GraphName array the chart title should use the title at position 0 of the GraphTitle array.

How can I fix this?


Code:
GraphTitle = Array("Actual Hours vs. Goal Hours", "Actual Days vs. Goal Days")
GraphName = Array("H1", "H2")
For r = 0 To UBound(GraphTitle)
For i = 0 To UBound(GraphName)

        Set MyChart = ActiveSheet.ChartObjects(GraphName(i)).Chart
               ' stuff with GraphName(i) here
   
        MyChart.SetElement (msoElementChartTitleAboveChart)
        
        MyChart.ChartTitle.Text = GraphTitle(r)


Next i
Next r
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
You only need one loop:

Code:
GraphTitle = Array("Actual Hours vs. Goal Hours", "Actual Days vs. Goal Days")
GraphName = Array("H1", "H2")
For i = LBound(GraphTitle) To UBound(GraphTitle)
    Set MyChart = ActiveSheet.ChartObjects(GraphName(i)).Chart
               ' stuff with GraphName(i) here
    MyChart.SetElement (msoElementChartTitleAboveChart)
    MyChart.ChartTitle.Text = GraphTitle(i)
Next i
 
Upvote 0
interesting...that works perfectly but I don't get it. How does the loop even know to use the GraphName array?


Code:
For i = LBound(GraphTitle) To UBound(GraphTitle)
The way I see it your code only tells the loop to look at the GraphTitle array. I would love to understand exactly how this works. Thanks for the help!!
 
Upvote 0
This is using the GraphName array:

Rich (BB code):
Set MyChart = ActiveSheet.ChartObjects(GraphName(i)).Chart

Your arrays are of equal size so you only need one loop to index into them.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,723
Members
452,939
Latest member
WCrawford

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