+ Reply to Thread
Results 1 to 9 of 9

XIRR function in VBA with dates in array

  1. #1
    Registered User
    Join Date
    08-08-2020
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    6

    XIRR function in VBA with dates in array

    Hello all! My first time here. This may be a very noob question, but I'm hoping to get some insight on why using dates stored in an array in VBA does not work with XIRR (or max) worksheetfunctions. Is there some conversion I need to do on the dates before passing them to the functions? In the array they are stored as #mm/dd/yyyy#, is this causing the issue?

    Thanks so much in advance.

    The date and amount values are stored with:
    Please Login or Register  to view this content.
    The XIRR call is:
    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827

    Re: XIRR function in VBA with dates in array

    I've seen this with other Excel functions. XIRR() is an Excel function, and Excel only knows two data types -- double and string. It doesn't know VBA's Date data type, so it doesn't know what to do with it. Try storing your dates as an array of doubles. Where are the dates coming from? If they are coming from Excel, then it should be enough to simply read them into an appropriate array. If they are coming from VBA, you may need to loop through and use CDbl() to convert from Date to Double.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    08-08-2020
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    6

    Re: XIRR function in VBA with dates in array

    Thanks. Tried that and got an error of "unable to get the xirr property of the worksheetfunction class". Will try to do some data type conversions and see if that makes a difference.

  4. #4
    Registered User
    Join Date
    08-08-2020
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    6

    Re: XIRR function in VBA with dates in array

    I was able to get the Max function working though by typing the dates as Long.
    Last edited by sch21c; 08-08-2020 at 10:45 AM.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827

    Re: XIRR function in VBA with dates in array

    Excel usually has no trouble converting numeric data types (Long, Integer, Single) to its native Double. If your dates do not contain time information, then they, too, could be stored as Long.

  6. #6
    Registered User
    Join Date
    08-08-2020
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    6

    Re: XIRR function in VBA with dates in array

    Tried using data types of Variant, Long and Double for the date array. Still not calculating the XIRR correctly. Returning a zero in the test case, should be returning .243. The max function did work with the data type change though.

  7. #7
    Registered User
    Join Date
    08-08-2020
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    6

    Re: XIRR function in VBA with dates in array

    Quote Originally Posted by MrShorty View Post
    Excel usually has no trouble converting numeric data types (Long, Integer, Single) to its native Double. If your dates do not contain time information, then they, too, could be stored as Long.
    The dates didn't have any time info. They were being store in the arrays with the #mm/dd/yyyy# values.

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827

    Re: XIRR function in VBA with dates in array

    Still not calculating the XIRR correctly. Returning a zero in the test case, should be returning .243.
    You haven't shared anything about your test case, but a case that should return 24.3% but returns 0% (any chance it is 2.98E-9?) sounds like an example where Excel's implementation of XIRR() fails to converge. We've talked about the instabilities in Excel's XIRR() implementation before (and noted that other spreadsheets seem more stable). Example threads:

    https://www.excelforum.com/excel-for...-rate-irr.html
    https://www.excelforum.com/excel-gen...rr-return.html

    Often, Excel's instability can be overcome by providing the optional "guess" parameter to the XIRR() function. I wonder what would happen (knowing that it should return 24.3%) if you tried:
    Advance_xirr = Application.Xirr(Payment_amount, Payment_date,0.25)

    At this point, I would suggest that debugging this needs to not only consider the data type issue but also needs to be aware of the possible instabilities in Excel's XIRR() function.

    PS. Just thought of this -- with some of the other questions about data types that have come up, is there any chance that you have dimmed Advance_xirr as long or integer? I know it seems like a silly mistake, but I have seen enough users make the mistake, that it occurred to me to check.

  9. #9
    Registered User
    Join Date
    08-08-2020
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    6

    Re: XIRR function in VBA with dates in array

    Quote Originally Posted by MrShorty View Post

    PS. Just thought of this -- with some of the other questions about data types that have come up, is there any chance that you have dimmed Advance_xirr as long or integer? I know it seems like a silly mistake, but I have seen enough users make the mistake, that it occurred to me to check.
    So, I had figured this out at the same time as you posted this. Yes, noob mistake (I did say I was a noob in the op, right?). I had the advance_xirr dimmed as a long. Set it to a double and working fine (with the date array dimmed as a long).

    Thanks for your help on this! Much appreciated!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Problem with indirect function in XIRR function
    By lynnsong986 in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 01-17-2020, 05:12 PM
  2. flexible XIRR with different starting dates
    By mrp2018 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-25-2019, 12:36 PM
  3. PRODUCT Array Function with Dates
    By andrewc in forum Excel General
    Replies: 1
    Last Post: 06-09-2019, 10:54 PM
  4. Replies: 4
    Last Post: 08-12-2018, 04:58 AM
  5. XIRR and Dates
    By Liebschki in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-07-2015, 03:13 AM
  6. XIRR in VBA not working with Array
    By ulfd in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 04-04-2013, 03:11 AM
  7. XIRR - Array Formula Error
    By Dtark513 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-31-2013, 04:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1