R
rafael garcia
I'm working on a macro to get a chart from a dynamic range of cells
(selected according to the date introduced for the user in the worksheet).
The problem is that I store the selected range of values in variant vectors
(1D arrays), as decimal types. In the below code these arrays are called
PVAC, SRDM, ISRM and TimeData. With some range the code works, but with the
most of them it doesn't it. Any idea? thank you
'-------------------------------
'To put the Chosen Range of Data in arrays
'Selected Data into vectors
RangeSize = endRow - starRow + 1 'Size of the Range of choosen Data
ReDim PVAC(RangeSize) 'vector size
ReDim SRDM(RangeSize) 'vector size
ReDim ISRM(RangeSize) 'vector size
ReDim TimeData(RangeSize) 'vector size
k = 0
Do Until (k = RangeSize)
PVAC(k) = CDec(Sheets("Alldata2").Cells(starRow + k, 14))
SRDM(k) = CDec(Sheets("Alldata2").Cells(starRow + k, 15))
ISRM(k) = CDec(Sheets("Alldata2").Cells(starRow + k, 16))
TimeData(k) = CDec(Sheets("Alldata2").Cells(starRow + k, 6))
k = k + 1
Loop
ReDim Preserve PVAC(RangeSize - 1)
ReDim Preserve SRDM(RangeSize - 1)
ReDim Preserve ISRM(RangeSize - 1)
ReDim Preserve TimeData(RangeSize - 1)
'----------------------------------------------
'Chart from the Selected Data
Charts.Add
ActiveChart.ChartType = xlXYScatterSmooth
'All de data as Range of Data
ActiveChart.SetSourceData Source:=Sheets("ALLDATA2").Range("N314575"),
PlotBy:=xlColumns
'Display the first serie
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = TimeData
ActiveChart.SeriesCollection(1).Values = PVAC
ActiveChart.SeriesCollection(1).Name = "=ALLDATA2!R2C14"
'Display the second serie
ActiveChart.SeriesCollection(2).XValues = TimeData
ActiveChart.SeriesCollection(2).Values = SRDM
ActiveChart.SeriesCollection(2).Name = "=ALLDATA2!R2C15"
'Display the third serie
ActiveChart.SeriesCollection(3).XValues = TimeData
ActiveChart.SeriesCollection(3).Values = ISRM
ActiveChart.SeriesCollection(3).Name = "=ALLDATA2!R2C16"
(selected according to the date introduced for the user in the worksheet).
The problem is that I store the selected range of values in variant vectors
(1D arrays), as decimal types. In the below code these arrays are called
PVAC, SRDM, ISRM and TimeData. With some range the code works, but with the
most of them it doesn't it. Any idea? thank you
'-------------------------------
'To put the Chosen Range of Data in arrays
'Selected Data into vectors
RangeSize = endRow - starRow + 1 'Size of the Range of choosen Data
ReDim PVAC(RangeSize) 'vector size
ReDim SRDM(RangeSize) 'vector size
ReDim ISRM(RangeSize) 'vector size
ReDim TimeData(RangeSize) 'vector size
k = 0
Do Until (k = RangeSize)
PVAC(k) = CDec(Sheets("Alldata2").Cells(starRow + k, 14))
SRDM(k) = CDec(Sheets("Alldata2").Cells(starRow + k, 15))
ISRM(k) = CDec(Sheets("Alldata2").Cells(starRow + k, 16))
TimeData(k) = CDec(Sheets("Alldata2").Cells(starRow + k, 6))
k = k + 1
Loop
ReDim Preserve PVAC(RangeSize - 1)
ReDim Preserve SRDM(RangeSize - 1)
ReDim Preserve ISRM(RangeSize - 1)
ReDim Preserve TimeData(RangeSize - 1)
'----------------------------------------------
'Chart from the Selected Data
Charts.Add
ActiveChart.ChartType = xlXYScatterSmooth
'All de data as Range of Data
ActiveChart.SetSourceData Source:=Sheets("ALLDATA2").Range("N314575"),
PlotBy:=xlColumns
'Display the first serie
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = TimeData
ActiveChart.SeriesCollection(1).Values = PVAC
ActiveChart.SeriesCollection(1).Name = "=ALLDATA2!R2C14"
'Display the second serie
ActiveChart.SeriesCollection(2).XValues = TimeData
ActiveChart.SeriesCollection(2).Values = SRDM
ActiveChart.SeriesCollection(2).Name = "=ALLDATA2!R2C15"
'Display the third serie
ActiveChart.SeriesCollection(3).XValues = TimeData
ActiveChart.SeriesCollection(3).Values = ISRM
ActiveChart.SeriesCollection(3).Name = "=ALLDATA2!R2C16"