ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Averaging in VB (https://www.excelbanter.com/excel-programming/297573-averaging-vbulletin.html)

Newbie

Averaging in VB
 
i'm writing a VB macro for excel and have run into a
problem: i have stored the addresses of cells into a
variable. i now would like to take the average of these
addresses using the variable onto a different Sheet. the
reason is that the number of rows and columns are supposed
to be arbitrary. here is an example of what i'm talking about:

Sheets("sheet2").select
temp = Range("B2", Range("B2","B2").End(xlDown)).Address
Range("A1").Select
' this next line is the problem
ActiveCell.Formula = "=AVERAGE(temp)"

for some reason excel wont let me take the average of
addresses stored in vatiables. any ideas?

Steve Garman

Averaging in VB
 
Try:
ActiveCell.Formula = "=AVERAGE(" & temp & ")"

NEWBIE wrote:
i'm writing a VB macro for excel and have run into a
problem: i have stored the addresses of cells into a
variable. i now would like to take the average of these
addresses using the variable onto a different Sheet. the
reason is that the number of rows and columns are supposed
to be arbitrary. here is an example of what i'm talking about:

Sheets("sheet2").select
temp = Range("B2", Range("B2","B2").End(xlDown)).Address
Range("A1").Select
' this next line is the problem
ActiveCell.Formula = "=AVERAGE(temp)"

for some reason excel wont let me take the average of
addresses stored in vatiables. any ideas?




All times are GMT +1. The time now is 10:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com