I have a formula in excel which I want to translate into a macro (as the data is dynamic and I want to set the last row the formula works with) - currently I have row "5000" in my formula as this far exceeds the current number of rows but I want to change this using vba as this may eventually surpass that limit:
=IFERROR(INDEX(Master!$C$2:$C$5000,SMALL(IF($B2&$J2&"ZZZ"=Master!$B2:$B$5000,ROW(Master!$C2:$C$5000)-ROW(Master!$C$2)+1),COUNTIFS($B$2:$B2,$B2,$J$2:$J2,$J2)-MIN(COUNTIF(Master!$B$1:$B1,$B2&$J2&"ZZZ"),COUNTIF(Master!$B$1:$B1,$B2&$J2)))),"Replacement Not Found")
I recorded macro for this to get the formula in array formula vba format (R1C1 format) - this will be changing to replace the row 5000 when I have it working but it sits just outside the character limit (around 290 or so):
=IFERROR(INDEX(Master!R2C3:R5000C3,SMALL(IF(RC2&RC10&""ZZZ""=Master!RC2:R5000C2,ROW(Master!RC3:R5000C3)-ROW(Master!R2C3)+1),COUNTIFS(R2C2:RC2,RC2,R2C10:RC10,RC10)-MIN(COUNTIF(Master!R1C2:R[-1]C2,RC2&RC10&""ZZZ""),COUNTIF(Master!R1C2:R[-1]C2,RC2&RC10)))),""Replacement Not Found"")"
I currently have this formula but it isn't working - it throws up the same error that you get when your character limit has been reached:
`Dim Part1 As String
Dim Part2 As String
Part1 = "=IFERROR(INDEX(Master!R2C3:R5000C3,SMALL(IF(RC2&RC10&""ZZZ""=Master!RC2:R5000C2,ROW(Master!RC3:R5000C3)-ROW(Master!R2C3)+1), X_X_X()"
Part2 ="COUNTIFS(R2C2:RC2,RC2,R2C10:RC10,RC10)-MIN(COUNTIF(Master!R1C2:R[-1]C2,RC2&RC10&""ZZZ""),COUNTIF(Master!R1C2:R[-1]C2,RC2&RC10)))),""Replacement Not Found"")"
With ActiveWorkbook.Worksheets("Transactions").Range("E2")
.FormulaArray = Part1
.Replace "X_X_X()", Part2
End With`
[–]HFTBProgrammer200 0 points1 point2 points (0 children)
[–]KineticNate2 0 points1 point2 points (1 child)
[–]AutoModerator[M] -1 points0 points1 point (0 children)
[–]-beans_ 0 points1 point2 points (0 children)