What is the best way to merge those both array :
Array1 |
---|
Red |
Orange |
Red |
Red |
Orange |
Array2 |
---|
3 |
7 |
9 |
15 |
32 |
The output excepted is :
Orange | Red |
---|---|
7 | 3 |
32 | 9 |
0 | 15 |
The Idea is to use this output array to do a stacked bar chart.
I've no Idea of how to do so. I thought about using loop in order to browse array 1 and 2 and then store in a new array values. But this seems quite time consuming. So what would be the most efficient way to do this ?
What I currently did is :
Set cht = output.ChartObjects("Chart 3").Chart
With cht
.ChartArea.ClearContents
.ChartType = xl3DColumnStacked
xdata = Array1
ydata = Array2
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = xdata
.SeriesCollection(1).Values = ydata
.Axes(xlCategory).TickLabelSpacing = 1
End With
Currently Array1
and Array2
are filled by this sample of code :
If (dbRecSet.RecordCount <> 0) Then
Do While Not dbRecSet.EOF
If dbRecSet.Fields(0).Value <> "" Then
ReDim Preserve Array1(cpt)
ReDim Preserve Array2(cpt)
Array1(cpt) = Replace(dbRecSet.Fields(0).Value, " ", Chr(13))
Array2(cpt) = dbRecSet.Fields(1).Value
cpt = cpt + 1
End If
dbRecSet.MoveNext
Loop
End If
The recordset looks like :
Color | Value |
---|---|
Red | 3 |
Orange | 7 |
Red | 9 |
Red | 15 |
Orange | 32 |
but it does not work as excepted so I think that :
xdata = Array1
ydata = Array2
Is the wrong thing there. So I think to make this work I have to merge my 2 arrays in one to do my stacked bar chart.
But I am not sure of this hypothesis since it seems possible to do stacked column chart with two arrays on this topic