Calculating averages in a group of numbers?

jimhatton
03-26-2003, 02:27 AM
I have uploaded a section from an excel datasheet, containing information about eye movements. I have limited visual basic knowledge and i am having difficulty writing a macro to organise the data. I wonder if someone could help? I need to find the mean of, say column I. Not the whole column, but say from the top of trial 7 to the gap at the bottom (1.89 - 0.34). So everytime the macro comes across a gap in a row it looks up to the last gap and finds the mean of those numbers, then continues until there is no more data. I have absolutely no idea where to start. Could anyone help?

italkid
03-26-2003, 02:51 AM
I dont see anythig in your attachment (a blank sheet).

What does "the mean" stands for ?

jimhatton
03-26-2003, 02:58 AM
I dont see anythig in your attachment (a blank sheet).

What does "the mean" stands for ?

By 'the mean' i am talking about 'the average'.

try this:

italkid
03-26-2003, 03:09 AM
Sorry no to see "average" in the tread title.

Could you not just put the "average" function in these cells (I11 & I19 in your example) and read those cell values ?

jimhatton
03-26-2003, 03:17 AM
Sorry no to see "average" in the tread title.

Could you not just put the "average" function in these cells (I11 & I19 in your example) and read those cell values ?

i could, but the page is about 4000 rows long multiplied by 10 subjects so this would take a long time, this i why i require a macro. I would also record a macro, but each trial is a different length depending on the subject.

italkid
03-26-2003, 04:32 AM
How it could work >

Look for the first empty cell in row ("I") from the end of te column to up.
once find make it the active cell.
Look for the first empty cell above (up) your active cell.
Take the average from all the cells between the active one and the empty one.
Put this average in the active cell.
Go up to the next empty cell and do the same (loop).

Just dont know anymore how to start looking for the first empty cell
beginning from the bottom of the sheet.....and i can't find it.

jimhatton
03-26-2003, 04:44 AM
How it could work >

Look for the first empty cell in row ("I") from the end of te column to up.
once find make it the active cell.
Look for the first empty cell above (up) your active cell.
Take the average from all the cells between the active one and the empty one.
Put this average in the active cell.
Go up to the next empty cell and do the same (loop).

Just dont know anymore how to start looking for the first empty cell
beginning from the bottom of the sheet.....and i can't find it.

Thanks for trying.

icjackson
03-26-2003, 07:33 AM
Following on from italkid's pseudocode:
Dim rFoundCell As Range
Dim sFirstCell As String
Dim rEndCell As Range
'look in the first column
With Worksheets(1).Range("A:A")
'find a non blank cell in column A (from the bottom up)
Set rFoundCell = .Find(What:="*", LookIn:=xlValues, SearchDirection:=xlPrevious)
If Not rFoundCell Is Nothing Then
sFirstCell = rFoundCell.Address
Do
'if it is not the first row, then add the formula
If rFoundCell.Row > 1 Then
'find the top of the range of numbers immediately above the found cell
Set rEndCell = Cells(rFoundCell.Row - 1, 9).End(xlUp)
'insert the average formula using RC specification
Cells(rFoundCell.Row, 9).Formula = "=Average(R[-" & rFoundCell.Row - rEndCell.Row & "]C:R[-1]C)"
End If
'find the next cell (up the page)
Set rFoundCell = .FindPrevious(rFoundCell)
Loop While Not rFoundCell Is Nothing And rFoundCell.Address <> sFirstCell
End If
End With

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum