macro problem - .SeriesCollection(i) number of parameters

cata

New Member
Joined
Aug 1, 2011
Messages
1
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
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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