To find Average

M

Murali G

Hello-

There is a requirement in my project to find the average of values in a
sheet. Values starts from A1 and goes till G20 (which keeps changing every
month). For each row we have to find the Average.
For example;
A B C D
-- -- -- --
10 20 10 40
30 40 20 50
50 60 30 60

For Row 'A' we have to find the Average, similarly for 'B','C' and 'D'.

Instead of doing manually is there any code to perform this task by writing
a macro.

Please let me know if you need any further details.

Regards,
Murali. G
 
M

Murali G

Yes, it is easier to write a function as you suggested. But as i said the
data keeps increasing, instead of writing a formula every month it is better
to write a macro which calculates the average every time by clicking a
button.

Please help.

Regards,
Murali. G
 
P

Patrick Molloy

why don't you put the avarage function into column A?
so A1:= =AVERAGE(B1:X1")
it will return the average where there are numbers and ignores nulls
 
D

Don Guillett

This will find the last ROW and delete it for the previous average. So,
first time put something in a last row to delete. Then if finds the longest
column on the page and puts the average of each column two cells below.

Sub findlastcellandaveragecolumns()
Rows(Cells(Rows.Count, 1).End(xlUp).Row).Delete
lr = Cells.Find(What:="*", After:=[A1], _
SearchDirection:=xlPrevious).Row

For i = 1 To _
Cells(1, Columns.Count).End(xlToLeft).Column
Cells(lr+2, i).Value = _
Application.Average(Cells(2, i).Resize(lr))
Next i
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top