James Chen
James Chen

Reputation: 873

Why does .Sum("B2:F2") generate "Unable to get the Property of the WorksheetFunction class" error?

Even when I try to sum a row of values. I tried worksheetfunction.mmult but I get the same error. Do I need to add more references to my Excel?

Sub GetObj()
Dim Obj As Double
Dim VB1, VB2, AESum As Double
Dim range1, range2, cell1, cell2 As Range

With Worksheets("Result")
    AESum = Application.WorksheetFunction.Sum("B2:F2")
End With

End Sub

Upvotes: 3

Views: 11543

Answers (4)

Singaravelan
Singaravelan

Reputation: 839

Excel.WorksheetFunction.Sum(Range("J7:J8")) 

this works for me!

Upvotes: 1

user2140261
user2140261

Reputation: 7993

You can change

AESum = Application.WorksheetFunction.Sum("B2:F2")

to

AESum = Application.WorksheetFunction.Sum(.Range("B2:F2"))

you could also evaluate the expression as:

AESum = [Sum(Result!B2:F2)]

Upvotes: 1

Peter Albert
Peter Albert

Reputation: 17475

Instead of Application.WorksheetFunction.Sum("B2:F2") use Application.WorksheetFunction.Sum(.Range("B2:F2"))!

Upvotes: 3

Siddharth Rout
Siddharth Rout

Reputation: 149305

On it's own "B2:F2" is just a string. If you want to use it as a range then you will have to specifically specify that.

Change

AESum = Application.WorksheetFunction.Sum("B2:F2")

to

AESum = Application.WorksheetFunction.Sum(.Range("B2:F2"))

Upvotes: 8

Related Questions