Macro to create average based on varying ranges

Jedit

New Member
Joined
Feb 8, 2013
Messages
27
I am trying to create a macro to take an average of various subsets of data embedded within a large set of data.

My current macro is:

Sub Step7()
'Relative turned on here
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "Average"
ActiveCell.Offset(0, 1).Range("A1").Select
' Dont use autosum. type this formula:
Selection.FormulaR1C1 = "=AVERAGE(R2C:R[-1]C)"
Selection.AutoFill Destination:=ActiveCell.Range("A1:G1"), Type:= _
xlFillDefault
ActiveCell.Range("A1:C1").Select
'Relative turned off here
ActiveCell.Rows("1:1").EntireRow.Select
ActiveCell.Activate
Selection.Font.Bold = True
Cells.Select
Selection.Columns.AutoFit
Range("A1").Select



End Sub


The macro reads my set of data and produces an average value at the end of the entire data list or upon a break of data.

However, the macro calculates the average from all data beginning at the top of the list. What I would like for the macro to do is:

Formulate an average based upon the active cell and break of information.

I need to use this macro for multiple data sets and multiple ranges of data (3 rows, 8 rows and 24 rows)

I believe this way I can still use the same macro to calculate the average for each subsection of data located in the same data set.

The following table is some of the data i need to calculate the average for:

I need to create average for 3 hour periods, 8 hours period, and 24 hour periods and I think my macro will work if I can make it so the range for my macro is from the active cell to the break of information ( which I would need to insert manually)

Thank you for any assistance you can provide.

Jedit
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]date/time[/TD]
[TD]conc[/TD]
[TD]flow[/TD]
[TD]w/s[/TD]
[TD]w/d[/TD]
[TD]at[/TD]
[TD]rhx[/TD]
[/TR]
[TR]
[TD]11/15/2012 19:00[/TD]
[TD].02[/TD]
[TD]16.7[/TD]
[TD].3[/TD]
[TD]351[/TD]
[TD]18.3[/TD]
[TD]41[/TD]
[/TR]
[TR]
[TD]11/15/2012 20:00[/TD]
[TD].019[/TD]
[TD]16.7[/TD]
[TD].3[/TD]
[TD]359[/TD]
[TD]18.7[/TD]
[TD]42[/TD]
[/TR]
[TR]
[TD]11/15/2012 21:00[/TD]
[TD].014[/TD]
[TD]16.7[/TD]
[TD].3[/TD]
[TD]354[/TD]
[TD]19.2[/TD]
[TD]42[/TD]
[/TR]
[TR]
[TD]11/15/2012 22:00[/TD]
[TD].019[/TD]
[TD]16.7[/TD]
[TD].3[/TD]
[TD]29[/TD]
[TD]19.7[/TD]
[TD]43[/TD]
[/TR]
[TR]
[TD]11/15/2012 23:00[/TD]
[TD].015[/TD]
[TD]16.7[/TD]
[TD].3[/TD]
[TD]48[/TD]
[TD]20[/TD]
[TD]44[/TD]
[/TR]
[TR]
[TD]11/16/2012 0:00[/TD]
[TD].018[/TD]
[TD]16.6[/TD]
[TD].3[/TD]
[TD]34[/TD]
[TD]20.2[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]11/16/2012 01:00[/TD]
[TD].014[/TD]
[TD]16.5[/TD]
[TD].3[/TD]
[TD]11[/TD]
[TD]20.4[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]11/16/2012 02:00[/TD]
[TD].015[/TD]
[TD]16.7[/TD]
[TD].3[/TD]
[TD]58[/TD]
[TD]20.4[/TD]
[TD]46[/TD]
[/TR]
[TR]
[TD]11/16/2012 03:00[/TD]
[TD].021[/TD]
[TD]16.7[/TD]
[TD].3[/TD]
[TD]1[/TD]
[TD]20.2[/TD]
[TD]47[/TD]
[/TR]
[TR]
[TD]11/16/2012 04:00[/TD]
[TD].018[/TD]
[TD]16.6[/TD]
[TD].3[/TD]
[TD]24[/TD]
[TD]19.8[/TD]
[TD]48[/TD]
[/TR]
[TR]
[TD]11/16/2012 05:00[/TD]
[TD].017[/TD]
[TD]16.7[/TD]
[TD].3[/TD]
[TD]26[/TD]
[TD]19.5[/TD]
[TD]48[/TD]
[/TR]
[TR]
[TD]11/16/2012 06:00[/TD]
[TD].022[/TD]
[TD]16.7[/TD]
[TD].3[/TD]
[TD]1[/TD]
[TD]19.2[/TD]
[TD]47[/TD]
[/TR]
[TR]
[TD]11/16/2012 07:00[/TD]
[TD].025[/TD]
[TD]16.5[/TD]
[TD].3[/TD]
[TD]351[/TD]
[TD]18.9[/TD]
[TD]48[/TD]
[/TR]
[TR]
[TD]11/16/2012 08:00[/TD]
[TD].021[/TD]
[TD]16.6[/TD]
[TD].3[/TD]
[TD]357[/TD]
[TD]18.7[/TD]
[TD]47[/TD]
[/TR]
[TR]
[TD]11/16/2012 09:00[/TD]
[TD].025[/TD]
[TD]16.7[/TD]
[TD].3[/TD]
[TD]358[/TD]
[TD]18.5[/TD]
[TD]47[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,223,610
Messages
6,173,339
Members
452,510
Latest member
RCan29

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