katieexcel
New Member
- Joined
- Feb 20, 2013
- Messages
- 4
Hiya,
I have some code that I think can be simlified, but I'm not sure how...
So I have defined two ranges, rcol1 and rcol2, and then I am plotting them.
rcol1 and rcol2 have the same columns but different rows (8 and 9 respectively). Is there a way of saying "rcol(j)" and "for j=0 to ..." and setting the row number in terms of j? Then plotting the series values in j?
xxxx
I have some code that I think can be simlified, but I'm not sure how...
Code:
Sub graph()
Sheets("New QC").Select
Dim i As Variant
Dim rrange1 As Range
Dim rrange2 As Range
Dim rcol1 As Range
Dim rcol2 As Range
Set rrange1 = Range(("e8"), ("s8"))
rrange1.Select
With Selection
Set rrange1 = Selection(1).Resize(Selection.Rows.Count)
Set rcol1 = rrange1
For i = 2 To 16 Step 2
Set rcol1 = Application.Union(rcol1, rrange1(, i - 1))
Next
End With
Set rrange2 = Range(("e9"), ("s9"))
rrange2.Select
With Selection
Set rrange2 = Selection(1).Resize(Selection.Rows.Count)
Set rcol2 = rrange2
For i = 2 To 16 Step 2
Set rcol2 = Application.Union(rcol2, rrange2(, i - 1))
Next
End With
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnStacked
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Values = rcol1
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Values = rcol2
End Sub
So I have defined two ranges, rcol1 and rcol2, and then I am plotting them.
rcol1 and rcol2 have the same columns but different rows (8 and 9 respectively). Is there a way of saying "rcol(j)" and "for j=0 to ..." and setting the row number in terms of j? Then plotting the series values in j?
xxxx