Excel Excel - average vba

Joined
May 6, 2011
Messages
13
Reaction score
0
Hi, i want to find the average of a range of cells (D11:D20) and insert it into D21 when the active cell row is 21

this should be pretty easy for the more technical people so a quick response would be appreciated.

it should start off like this ;

if activecell.row = 21 then....

Cheers in advance
 
Hi,

Will your range be always be D11:D20?

if it's the case : this should help you :

Range("D21").Value = Application.WorksheetFunction.Sum(Range("D11:D20")) / Range("D11:D20").Count

Sifou
 
cuddihy2k7,

You may need to compare the value in your active cell to compare it to the value '21'
psudocode:
declare a variable to capture the value of the active cell (variable name = activecell.value)
use the worksheet change event
on change if the active cell value = '21' then execute the line of code from Sifou
release variable values
Or you may ask the moderator if it is OK to send a sample workbook via private message and I could provide the macro.

Stoneboysteve
 
thanks lads, this helped a lot, I just needed this bit of code and everything else seems to be working fine, this is just what I need in the spreadsheet that should be soon sent out to multiple users
 
Back
Top