Vba loop select range: Nth cell in column

katieexcel

New Member
Joined
Feb 20, 2013
Messages
4
Hii, I need help with some code... I am stuck and have a feeling I'm nowhere near solving this myself! :(

I have 24 sets of data in columns 3-26.
Data is in rows 2-n (all datasets are same length). 'n' is typically around 2000.
I am plotting 24 series on one chart. With about 2000 data points it's hard to make any sense of each series, so I want to use fewer data points.
I want to plot every 20th data point. Then I will have 100 points for each of my 24 series.
[Eventually, I might want to take an average of every 20 datapoints and plot 100 mean values (x 24) but I can't face that right now!]

This is code I have come up with....
Code:
With Worksheets(var)  
Set rrange = .Range("C2", .Cells(.Rows.Count, "c").End(xlUp))  
End With
For i = 1 To 24
For r = 1 To rrange.Rows.Count Step 20
If r = 1 
Then
 Set yvals = rrange(r, i) 
Else
Set yvals = Union(rrange(r, i), yvals)
End If 
Next r
Next i

This code is plotting the 24th series, which is in column 26. I don't understand why it is plottin the 24th series when it says range "c2"? Surely it should plot the first series, which is in that column?

I am not sure how to make this for for all i, I tried
Code:
Set vals(i)=range(r,(i))
but it didn't work. Even if it did work, how do I write
Code:
Set rrange = .Range("&i&2", .Cells(.Rows.Count, "&i&").End(xlUp))
correctly?

THANKSSSSSS, I'm so bad at this ! x
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Maybe, !! Try changing the line in red.
Rich (BB code):
If Yvals Is Nothing Then
 Set Yvals = Rrange(r, I)
Else
Set Yvals = Union(Rrange(r, I), Yvals)
End If
Next r
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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