VBA Macro to Average Non-Contiguous but Regular Interval Cells

SianB

New Member
Joined
Jun 8, 2013
Messages
1
Hi, I have a worksheet with 35,136 rows of data. I want to calculate the average of every 4th cell in the same column. Is there a way to create a macro to select every 4th cell in the average formula? If so, can I then substitute min and max for average? Thanks.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi

You should be able to us a native formula for that.

Given the column of values:

Excel 2010
A
1Value
2829
3811
4351
5971
6912
7635
8105
9114
10708
11578
1262
13549
14934
15405
1690
17724
18236
19873
20409
Sheet1


We can use the MOD function to establish a pattern:

Excel 2010
AB
1ValuePattern
28291
38112
43513
59710
69121
76352
81053
91140
107081
115782
12623
135490
149341
154052
16903
177240
182361
198732
204093
Sheet1
Cell Formulas
RangeFormula
B2=MOD(ROW()-ROW($A$1),4)


And use this approcah to calc a min/max/average/sum etc. As follows:

Excel 2010
ABCD
1ValueN4
2829
3811Min114
4351Max971
5971Average589.5
6912Sum2358
7635
8105
9114
10708
11578
1262
13549
14934
15405
1690
17724
18236
19873
20409
Sheet1
Cell Formulas
RangeFormula
D3{=MIN(IF(MOD(ROW($A$2:$A$20)-ROW($A$1),4)=0,$A$2:$A$20))}
D4{=MAX(IF(MOD(ROW($A$2:$A$20)-ROW($A$1),4)=0,$A$2:$A$20))}
D5{=AVERAGE(IF(MOD(ROW($A$2:$A$20)-ROW($A$1),4)=0,$A$2:$A$20))}
D6{=SUM(IF(MOD(ROW($A$2:$A$20)-ROW($A$1),4)=0,$A$2:$A$20))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0

Forum statistics

Threads
1,216,150
Messages
6,129,154
Members
449,488
Latest member
qh017

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