Hi (please excuse the bad formatting and conventions I am not a coder)
I have a VBA function that calculates the time weighted average given a table of dates and values. The problem is that I cannot pass the iterator through one of the excel functions.
The issue arises in the following line: totalWeighting = totalWeighting + Cells(Application.Match(start_date, dateRange, 1), userCodeColumn)
When using start_date the function works fine (note that I have a bunch of other code to Dim variables which I have excluded). However, when you replace start_date with "d", it returns #value.
Function TimeWeightedAverage(start_date, end_date)
totalWeighting = 0
For d = start_date To end_date If WorksheetFunction.Weekday(d, 11) < 6 Then totalWeighting = totalWeighting + Cells(Application.Match(start_date, dateRange, 1), userCodeColumn) Else d = d + 1 End If Next
Any thoughts would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire