Hi,
I am trying to implement the following function but I just can't get a value. The goal is to sum a row of numbers by matching a date in order to find the correct column and then to sum only the values that match a String in column 4.
Any help would be appreciated
Public Function Calc(Collateral As String, Datum As Integer) As Integer
Dim Column As Integer
Dim rngRequested As Range
Dim rngRequested2 As Range
Dim Test As String
Dim Weight As Integer
Dim Result As Integer
Dim i As Integer
Weight = 0
Set rngRequested2 = Sheets("TotalDomestic").Range("A2:CC650")
Set rngRequested = Sheets("TotalDomestic").Range("A1:CC1")
Column = Application.WorksheetFunction.Match(CLng(Datum), rngRequested, 0)
For i = 1 To 644 Step 1
Test = Application.WorksheetFunction.Index(rngRequested2, i, 4)
If Test = Collateral Then
Result = Application.WorksheetFunction.Index(rngRequested2, i, Column)
Else
Result = 0
End If
Weight = Weight + Result
Next i
Calc = Weight
End Function
Thx
I am trying to implement the following function but I just can't get a value. The goal is to sum a row of numbers by matching a date in order to find the correct column and then to sum only the values that match a String in column 4.
Any help would be appreciated
Public Function Calc(Collateral As String, Datum As Integer) As Integer
Dim Column As Integer
Dim rngRequested As Range
Dim rngRequested2 As Range
Dim Test As String
Dim Weight As Integer
Dim Result As Integer
Dim i As Integer
Weight = 0
Set rngRequested2 = Sheets("TotalDomestic").Range("A2:CC650")
Set rngRequested = Sheets("TotalDomestic").Range("A1:CC1")
Column = Application.WorksheetFunction.Match(CLng(Datum), rngRequested, 0)
For i = 1 To 644 Step 1
Test = Application.WorksheetFunction.Index(rngRequested2, i, 4)
If Test = Collateral Then
Result = Application.WorksheetFunction.Index(rngRequested2, i, Column)
Else
Result = 0
End If
Weight = Weight + Result
Next i
Calc = Weight
End Function
Thx