Can't get WorksheetFunction.Average to work.

  • Thread starter Thread starter sesheldon
  • Start date Start date
S

sesheldon

Guest
Hi all,

I am trying to compute the average of a range of cells and assign it to a double variable.

Partial code:

Dim objAppExcel As Excel.Application
Dim objBook As Excel._Workbook = Nothing
Dim objBooks As Excel.Workbooks = Nothing
Dim objSheets As Excel.Sheets = Nothing
Dim objSheet As Excel._Worksheet = Nothing

objAppExcel = New Excel.Application()
objAppExcel.Visible = False
objBooks = objAppExcel.Workbooks
objBook = objAppExcel.Workbooks.Open(CurrentPath & "\myfile.xls")
objSheets = objBook.Worksheets
objSheet = objSheets(1)

Dim StartupAverage As Double = Application.WorksheetFunction.Average("B5:E5")


This returns and error, "Reference to a non-shared member requires an object reference."

Can anyone tell me the correct syntax to get the average of the range of cells?

Thanks,

Continue reading...
 
Back
Top