Hi again Turen,
Irrespective of how may values are to be averaged, the logic for the
programming is the same. I originally tested it with the data you supplied.
However, I have modified it so that there is now an InputBox so that when you
run the macro you can enter the number of values to be averaged and the
results will always be in column B. Any exisiting values in column B will be
deleted and replaced with the new values each time you run the macro.
Set up your Sheet1 with Data in column A as per the sample data you
originally posted and insert a column header in cell B1 called 'Averages' (or
whatever name you want to use.)
Sub Averages()
Dim ws1 As Worksheet
Dim rng1 As Range
Dim i As Long
Dim aveGroup As Variant
Dim colNbr As Long 'Column for results
aveGroup = InputBox _
("Enter the number of cells to average" _
& Chr(13) & "Cancel to exit.")
If aveGroup = "" Then
MsgBox "User cancelled - Processing aborted"
End
End If
Set ws1 = Sheets("Sheet1")
'Assign range to a variable
With ws1
Set rng1 = Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlUp))
End With
'Set colNbr for column to place results
colNbr = 2
'Clear existing data from column 2
ws1.Range(Cells(2, colNbr), _
Cells(Rows.Count, colNbr).End(xlUp)).Clear
With rng1
For i = 1 To .Rows.Count Step aveGroup
ws1.Cells(Rows.Count, colNbr).End(xlUp).Offset(1, 0) _
= WorksheetFunction.Average(.Cells(i, 1), _
.Cells(i + aveGroup - 1, 1))
Next i
End With
End Sub
Regards,
OssieMac