excel - Find average of several cells then autofill -


i looking find average of cells a2:d2 , place them e2 auto fill equation rest of 500 or e cells. here have far:

sub average () dim nrows integer dim ncols integer  ncols = range(range("a2"), range("a2").end(xltoright)).columns.count nrows = range(range("a2"), range("a2").end(xldown)).rows.count range("e2").formular1c1 = "=average(r[]c[ " & ncols & "]:r[]c[])"  end sub 

the macro below put average of d in column e each row , pull formula down last row of worksheet.

sub average()  dim lrow long dim acell string dim col string      range("e2").select     activecell.formular1c1 = "=average(rc[-4]:rc[-1])"     lrow = worksheetfunction.max(range("a65536").end(xlup).row,      range("b65536").end(xlup).row, range("c65536").end(xlup).row)     acell = range("e2").address(rowabsolute:=false, columnabsolute:=false)     col = left(acell, 1)     range(acell & ":" & acell).autofill range(acell & ":" & col & lrow) 

end sub


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -