Using a Dynamic Array when adding a chart series

dcanham

Active Member
Joined
Jun 7, 2006
Messages
306
Can anyway suggest a way to use the dynamic array SalesNumbersArray() to fill out the XValues for the chart? Or lacking that a better way to fill the values? Thanks.


Code:
    ' determining number of datapoints
    nSeriesDataPoints = (nSeriesTotalDays / nSeriesDivisor)
    
    ' initializing array
    Dim SalesNumbersArray(nSeriesDataPoints) As Double
    
    ' loop for gathering sales
    Dim nLoop As Integer
    Dim nTotalSales As Double
    For nLoop = 0 To (nSeriesDataPoints - 1)
        ' getting total sales for this iteration
        nTotalSales = SUM_SALES_RANGE(sProductCode, nSeriesDivisor, (dStartDate + (nDivisor * nLoop)))
        
        ' placing total in array
        SalesNumbersArray(nLoop) = nTotalSales
    Next nPoints
    
    ' adding series
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(nSeriesCounter).Name = sProductCode
    ActiveChart.SeriesCollection(nSeriesCounter).XValues = SalesNumbersArray()
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You're going to run into the limit of around 250 (no, it's less than 256, but I don't know exactly what it is) characters for the literal array of values:

{1.23456,1.34689,2.98765}

That's 25 characters for three values, and Excel is carrying more digits than that for each.

The best way is to dump the array into the worksheet, and use the worksheet range as the chart data source.
 
Upvote 0
Thanks...I like that way better. Its a good way to see exactly what numbers came up outside of execution.
 
Upvote 0
It's so much easier in many ways to dump the data somewhere where you can see them, or use them in another way, or even just debug the process. Sometimes people are so intent on hiding numbers, using them directly in a chart, or saving cells that they forget how important it is to be able to access them.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,685
Members
448,978
Latest member
rrauni

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