XIRR - naming ranges to include monthly cash flows only
Ok I wrote a macro that gave me a range to feed the IRR function (variables are for other IRRs I need to add later) but the last line didn't work Range("E180").Formula = "=XIRR(" & str & ")", the str is ok though, can someone please help me fix it?
PHP Code:
Sub CalculateIrrs() Dim c As Range Dim cRow As Integer, startcol As Integer, lastcol As Integer Dim rng1 As Range Dim strSearch As String Dim Cell As Range Dim i As Integer, j As Integer Dim str As String, addi As String Dim Columnnumber1, Columnnumber2 Dim ColumnLetter1 As String, ColumnLetter2 As String Worksheets("Model").Activate startcol = 6 lastcol = Worksheets("Model").Cells(6, Columns.Count).End(xlToLeft).Column strSearch = "UL PT Net Flows - Unlevered Pre-Tax" Set rng1 = Range("B:B").Find(strSearch, , xlValues, xlWhole) rng1.Select Set c = ActiveCell cRow = c.Row Columnnumber1 = startcol j = Worksheets("Inputs").Range("ModelLastYear").Value - Worksheets("Inputs").Range("ModelFirstYear").Value + 1 For i = 1 To j 'MsgBox i Columnnumber2 = Columnnumber1 + 11 ColumnLetter1 = Split(Cells(1, Columnnumber1).Address, "$")(1) 'MsgBox ColumnLetter1 ColumnLetter2 = Split(Cells(1, Columnnumber2).Address, "$")(1) 'MsgBox ColumnLetter2 addi = ColumnLetter1 & cRow & ":" & ColumnLetter2 & cRow str = str & "," & addi
Columnnumber1 = Columnnumber2 + 2 Next str = Right$(str, (Len(str) - Len(","))) MsgBox str Range("E180").Formula = "=XIRR(" & str & ")" End Sub
thanks!
Last edited by lynnsong986; 01-17-2020 at 02:54 PM.
Re: XIRR - naming ranges to include monthly cash flows only
Thanks very much for replying. Ace_XL provided me with a very nice formula that does what I need. Here is the link - I also posted it in the formula section as the problem is more about the formula.
Bookmarks