Function getDividends(sRIC As String, dInception As Date, dSettlementDate As Date, sSheet As String)
Dim lDividendsMaxRow As Long: lDividendsMaxRow = 0
Dim i As Long: i = 2
Dim bPresentRIC As Boolean: bPresentRIC = False
Dim iCountDividends As Integer: iCountDividends = 0
Dim j As Integer: j = 1
ActiveWorkbook.Sheets("Dividends").Activate
lDividendsMaxRow = Cells(65536, 1).End(xlUp).Row
sError = ""
For i = 2 To lDividendsMaxRow
If Cells(i, 1) = sRIC Then
bPresentRIC = True
If Cells(i, 2) > dInception And Cells(i, 2) < dSettlementDate Then
iCountDividends = iCountDividends + 1
End If
End If
Next i
ReDim vDividends(iCountDividends, 2)
For i = 2 To lDividendsMaxRow
If Cells(i, 1) = sRIC Then
If Cells(i, 2) > dInception And Cells(i, 2) < dSettlementDate Then
vDividends(j, 1) = Cells(i, 2)
vDividends(j, 2) = Cells(i, 6)
j = j + 1
End If
End If
Next i
If bPresentRIC = False Then
sError = "Error: the RIC '" & sRIC & "' is not referenced in 'Dividends' sheet!"
MsgBox sError
End If
ActiveWorkbook.Sheets(sSheet).Activate
End Function