I am performing a VB function to sort out cumulative amount within a specified period with different categories. The objective is for personnel account expenses.
For example, I have in a sheet “tmp” in column A some dates, in column B a category (eg. Salary, Transport …) and in column C the values.
I want to define a function and I have tried to set:
Function Cumulatif(Categorie As String, Debut As Date, Fin As Date) As Double
' Do the sum of a category between a starting and ending date specified
Dim Operations As Variant
Dim SpecificSum As Double
Dim i As Integer
Operations = ThisWorkbook.Sheets("tmp").Range("A1:C3")
For Each Row In Operations.Rows
SpecificSum = 0
Next
Cumulatif = SpecificSum
End Function
But I don’t really know how to get the values from another sheet and do the loop in the range to set this sum. Can somebody help me on this?
The assigment to operations needs to be an object assignment, meaning: use Set (not Let/default).
Set Operations = ThisWorkbook.Sheets(“tmp”).Range(“A1:C3)
You can get the values from the other sheet (assuming you mean “tmp”) as follows
I think you’d be better off having the function take an additional range parameter and supplying Sheet1!A as an argument; this way Excel will know when it needs to recalculate.
And call Cumulatif using such a formula: