Weilon Sung
Technical User
Hi Guys,
I build my macro according to the thread and don't get any results but Errors. I googled since 2 days for some Inputs. At least the Problem can come from some data Settings. I tried all the ways I know but it just didnt work...
my codes below. Just the last row doesn't run and gives me permanent the 1004 msg "Unable to get the Xirr property of the WorksheetFunction class"
For debug I tried
- add libery like Excel 14.0, ATP 2.0 Type
- Change the declaration of the range payments and Dates into variant
- Change the language Settings from german to US to get the correctly Date-Format in VBA
I build my macro according to the thread and don't get any results but Errors. I googled since 2 days for some Inputs. At least the Problem can come from some data Settings. I tried all the ways I know but it just didnt work...
my codes below. Just the last row doesn't run and gives me permanent the 1004 msg "Unable to get the Xirr property of the WorksheetFunction class"
For debug I tried
- add libery like Excel 14.0, ATP 2.0 Type
- Change the declaration of the range payments and Dates into variant
- Change the language Settings from german to US to get the correctly Date-Format in VBA
Code:
Public Function AccessXIRR(Domain As String, PaymentField As String, DateField As String, PK_Field As String, PK_Value As Variant, Optional PK_IsText As Boolean = False, Optional GuessRate As Double = 0.1) As Variant
Dim Payments()
Dim Dates()
Dim rs As DAO.Recordset
Dim strSql As String
Dim i As Integer
If PK_IsText Then PK_Value = "'" & PK_Value & "'"
strSql = "SELECT " & PaymentField & ", " & DateField & " FROM " & Domain & " WHERE " & PK_Field & " = " & PK_Value & " ORDER BY " & DateField
Set rs = CurrentDb.OpenRecordset(strSql)
ReDim Payments(rs.RecordCount - 1)
ReDim Dates(rs.RecordCount - 1)
Do While Not rs.EOF
Payments(i) = rs.Fields(PaymentField).Value
Dates(i) = rs.Fields(DateField).Value
Debug.Print i
i = i + 1
rs.MoveNext
Loop
controll1 = Excel.Application.Sum(Payments)
controll2 = Excel.Application.WorksheetFunction.XIRR(Payments, Dates)
what else I can do?