Ting Ping
Ting Ping

Reputation: 1145

Unable to get the Sumif property of the worksheetfunction Class

Can anyone explain what I could do to fix this?

enter image description here

Here's the current code:

SumFinalUnusedSPQCement = WorksheetFunction.Sum(Application.WorksheetFunction.SumIf(Range("V4:V" & lastRow + 3), ">0", "B4:B" & lastRow + 3))
SumFinalUnusedSPQSand = WorksheetFunction.Sum(Application.WorksheetFunction.SumIf(Range("W4:W" & lastRow + 3), ">0", "C4:C" & lastRow + 3))
SumFinalUnusedSPQAggregate = WorksheetFunction.Sum(Application.WorksheetFunction.SumIf(Range("X4:X" & lastRow + 3), ">0", "D4:D" & lastRow + 3))

Upvotes: 2

Views: 6091

Answers (1)

Siddharth Rout
Siddharth Rout

Reputation: 149305

You are missing the Range before B4:B and similarly for the others. It should be

SumFinalUnusedSPQCement = Application.WorksheetFunction.SumIf( _
                                      Range("V4:V" & lastRow + 3), _
                                      ">0", _
                                      Range("B4:B" & lastRow + 3) _
                                      )

Also you do not need WorksheetFunction.Sum.

Upvotes: 3

Related Questions