setting DSUM criteria in a VBA function

E

excelman

How is the criteria changed?
This cause an error:
Workbooks("Tracker.xls").Sheets("Purchase").Range("H6").Value = 1

Function getSetTotal(sSet As String) As Currency
' Return the total purchases for sSet
'
Dim wsPurchase As Worksheet
Dim rDB As Range ' Database
Dim rColumn ' Database column to sum the amount for sSet
Dim rCriteria As Range
Dim total As Currency

Set wsPurchase = Worksheets("Purchase")
Set rDB = wsPurchase.Range("dbPURCHASE")
rColumn = "Amount"
Set rCriteria = wsPurchase.Range("H5:H6")
'Workbooks("Tracker.xls").Sheets("Purchase").Range("H6").Value = 1

total = Application.WorksheetFunction.DSum(rDB, rColumn, rCriteria)
'MsgBox "total: " & total
getSetTotal = total
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top