Hello,
I'd like to know if there is any way to have a variable number of parameters when creating a chart from multiple sets of numbers. I want to be able to use up to 9 sets, and using if's or case doesn't seem to be too efficient..
Here's that part of my code:
With ActiveChart
.ChartType = xlXYScatterLines
For i = 1 To CInt(IScale)
If step = 3 Then
.SeriesCollection.NewSeries
With .SeriesCollection(i)
.XValues = _
"=('Results'!R" & CInt(fchar) + i - 1 & "C" + fchac + ",'Results'!R" & IScale + CInt(fchar) + i - 1 & "C" + fchac + ",'Results'!R" & 2 * IScale + CInt(fchar) + i - 1 & "C" + fchac + ")"
.Values = _
"=('Results'!R" & CInt(fcvar) + i - 1 & "C" + fcvac + ",'Results'!R" & IScale + CInt(fcvar) + i - 1 & "C" + fcvac + ",'Results'!R" & 2 * IScale + CInt(fcvar) + i - 1 & "C" + fcvac + ")"
.Name = "='Results'!R" & CInt(LegRow) + i - 1 & "C" + LegCol + ""
End With
Else
If step = 2 Then
.SeriesCollection.NewSeries
With .SeriesCollection(i)
.XValues = _
"=('Results'!R" & CInt(fchar) + i - 1 & "C" + fchac + ",'Results'!R" & IScale + CInt(fchar) + i - 1 & "C" + fchac + ")"
.Values = _
"=('Results'!R" & CInt(fcvar) + i - 1 & "C" + fcvac + ",'Results'!R" & IScale + CInt(fcvar) + i - 1 & "C" + fcvac + ")"
.Name = "='Results'!R" & CInt(LegRow) + i - 1 & "C" + LegCol + ""
End With
Else
If step = 1 Then
.SeriesCollection.NewSeries
With .SeriesCollection(i)
.XValues = _
"=('Results'!R" & CInt(fchar) + i - 1 & "C" + fchac + ")"
.Values = _
"=('Results'!R" & CInt(fcvar) + i - 1 & "C" + fcvac + ")"
.Name = "='Results'!R" & CInt(LegRow) + i - 1 & "C" + LegCol + ""
End With
End If
End If
End If
Next i
.HasTitle = True
.ChartTitle.Characters.Text = ChartName
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = ChartX
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = ChartY
.Location Where:=xlLocationAsObject, Name:=WSheet
End With
I've tried for 3 sets so far and it works, but i hope someone can give me some other - more intelligent - solution
Thanks,
Catalina
I'd like to know if there is any way to have a variable number of parameters when creating a chart from multiple sets of numbers. I want to be able to use up to 9 sets, and using if's or case doesn't seem to be too efficient..
Here's that part of my code:
With ActiveChart
.ChartType = xlXYScatterLines
For i = 1 To CInt(IScale)
If step = 3 Then
.SeriesCollection.NewSeries
With .SeriesCollection(i)
.XValues = _
"=('Results'!R" & CInt(fchar) + i - 1 & "C" + fchac + ",'Results'!R" & IScale + CInt(fchar) + i - 1 & "C" + fchac + ",'Results'!R" & 2 * IScale + CInt(fchar) + i - 1 & "C" + fchac + ")"
.Values = _
"=('Results'!R" & CInt(fcvar) + i - 1 & "C" + fcvac + ",'Results'!R" & IScale + CInt(fcvar) + i - 1 & "C" + fcvac + ",'Results'!R" & 2 * IScale + CInt(fcvar) + i - 1 & "C" + fcvac + ")"
.Name = "='Results'!R" & CInt(LegRow) + i - 1 & "C" + LegCol + ""
End With
Else
If step = 2 Then
.SeriesCollection.NewSeries
With .SeriesCollection(i)
.XValues = _
"=('Results'!R" & CInt(fchar) + i - 1 & "C" + fchac + ",'Results'!R" & IScale + CInt(fchar) + i - 1 & "C" + fchac + ")"
.Values = _
"=('Results'!R" & CInt(fcvar) + i - 1 & "C" + fcvac + ",'Results'!R" & IScale + CInt(fcvar) + i - 1 & "C" + fcvac + ")"
.Name = "='Results'!R" & CInt(LegRow) + i - 1 & "C" + LegCol + ""
End With
Else
If step = 1 Then
.SeriesCollection.NewSeries
With .SeriesCollection(i)
.XValues = _
"=('Results'!R" & CInt(fchar) + i - 1 & "C" + fchac + ")"
.Values = _
"=('Results'!R" & CInt(fcvar) + i - 1 & "C" + fcvac + ")"
.Name = "='Results'!R" & CInt(LegRow) + i - 1 & "C" + LegCol + ""
End With
End If
End If
End If
Next i
.HasTitle = True
.ChartTitle.Characters.Text = ChartName
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = ChartX
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = ChartY
.Location Where:=xlLocationAsObject, Name:=WSheet
End With
I've tried for 3 sets so far and it works, but i hope someone can give me some other - more intelligent - solution
Thanks,
Catalina