HI ALL,
THIS IS MY FIRSTPOST SO HOPEFULLY I'M IN LINE W FORUM POLICIES.
I HAVE SET UP A MACRO TO PULL DATA THROUGH FROM A SECOND OPEN WORKBOOK TO A SHEET. IN THIS SHEET I WANT TO USE A FEW OF THE DATA POINTS TO CALCULATE A VALUE.
I HAVE THE FOLLOWING FORMULA THAT NEEDS TO BE APPLIED TO THE RANGE OF CELLS, WHICH ARE DYNAMIC BASED UPON THE ACTIVE RANGE OF THE OTHER WORKBOOK:
=MAX(INDIRECT($CM$1&$CM$2&ROW(CF13)),INDIRECT($CM$1&$CK$3&ROW(CF13)))+(SUMIF(INDIRECT($CM$1&$CK$1&$CG$1&":"&$CK$1&$CG$2),INDIRECT($CM$1&$CK$1&ROW(CF13)),INDIRECT($CM$1&$CK$2&$CG$1&":"&$CK$2&$CG$2))-SUMIF(INDIRECT($CM$1&$CK$1&$CG$1&":"&$CK$1&$CG$2),INDIRECT($CM$1&$CK$1&ROW(CF13)),INDIRECT($CM$1&$CK$3&$CG$1&":"&$CK$3&$CG$2)))
HOWEVER, THE RANGE CAN BE IN EXCESS OF 60000 ROWS.
AS SUCH I WANT TO AUTOMATE ON VBA TO TAKE SOME OF THE BURDEN OFF.
THUS FAR I HAVE PRODUCED THE FOLLOWING:
Sub Macro5()
'
' Macro5 Macro
'
'
Dim PartX As String
Dim PartY As String
Dim PartZ As String
PartX = "=MAX(INDIRECT(R1C91&R2C91&ROW(RC)),INDIRECT(R1C91&R3C89&ROW(RC)))""+""X_X_X())"
PartY = "=SUMIF(INDIRECT(R1C91&R1C89&R1C85&"":""&R1C89&R2C85),INDIRECT(R1C91&R1C89&ROW(RC)),INDIRECT(R1C91&R2C89&R1C85&"":""&R2C89&R2C85))""-""Y_Y_Y())"
PartZ = "=SUMIF(INDIRECT(R1C91&R1C89&R1C85&"":""&R1C89&R2C85),INDIRECT(R1C91&R1C89&ROW(RC)),INDIRECT(R1C91&R3C89&R1C85&"":""&R3C89&R2C85))"
With Sheets(3).Range("CF6:CF10")
.FormulaArray = PartX
.Replace "X_X_X())", PartY
.Replace "Y_Y_Y())", PartZ
End With
End Sub
NOTE THAT THE RANGE ABOVE IS JUST A PROXY WHILST I GET THE FORMULA TO WORK - SO ANY ADVICE ON HOW TO LINK THIS TO SOME SORT OF ACTIVE DATA ROW # WOULD BE AWESOME!
FRUSTRATINGLY I STILL GET THE "UNABLE TO SET THE FORMULAARRAY PROPERTY OF THE RANGE CLASS" MESSAGE.
ANY SUGGESTIONS ON IMPROVEMENT WOULD BE MUCH APPRECIATED!
THANKS,
WE2286
THIS IS MY FIRSTPOST SO HOPEFULLY I'M IN LINE W FORUM POLICIES.
I HAVE SET UP A MACRO TO PULL DATA THROUGH FROM A SECOND OPEN WORKBOOK TO A SHEET. IN THIS SHEET I WANT TO USE A FEW OF THE DATA POINTS TO CALCULATE A VALUE.
I HAVE THE FOLLOWING FORMULA THAT NEEDS TO BE APPLIED TO THE RANGE OF CELLS, WHICH ARE DYNAMIC BASED UPON THE ACTIVE RANGE OF THE OTHER WORKBOOK:
=MAX(INDIRECT($CM$1&$CM$2&ROW(CF13)),INDIRECT($CM$1&$CK$3&ROW(CF13)))+(SUMIF(INDIRECT($CM$1&$CK$1&$CG$1&":"&$CK$1&$CG$2),INDIRECT($CM$1&$CK$1&ROW(CF13)),INDIRECT($CM$1&$CK$2&$CG$1&":"&$CK$2&$CG$2))-SUMIF(INDIRECT($CM$1&$CK$1&$CG$1&":"&$CK$1&$CG$2),INDIRECT($CM$1&$CK$1&ROW(CF13)),INDIRECT($CM$1&$CK$3&$CG$1&":"&$CK$3&$CG$2)))
HOWEVER, THE RANGE CAN BE IN EXCESS OF 60000 ROWS.
AS SUCH I WANT TO AUTOMATE ON VBA TO TAKE SOME OF THE BURDEN OFF.
THUS FAR I HAVE PRODUCED THE FOLLOWING:
Sub Macro5()
'
' Macro5 Macro
'
'
Dim PartX As String
Dim PartY As String
Dim PartZ As String
PartX = "=MAX(INDIRECT(R1C91&R2C91&ROW(RC)),INDIRECT(R1C91&R3C89&ROW(RC)))""+""X_X_X())"
PartY = "=SUMIF(INDIRECT(R1C91&R1C89&R1C85&"":""&R1C89&R2C85),INDIRECT(R1C91&R1C89&ROW(RC)),INDIRECT(R1C91&R2C89&R1C85&"":""&R2C89&R2C85))""-""Y_Y_Y())"
PartZ = "=SUMIF(INDIRECT(R1C91&R1C89&R1C85&"":""&R1C89&R2C85),INDIRECT(R1C91&R1C89&ROW(RC)),INDIRECT(R1C91&R3C89&R1C85&"":""&R3C89&R2C85))"
With Sheets(3).Range("CF6:CF10")
.FormulaArray = PartX
.Replace "X_X_X())", PartY
.Replace "Y_Y_Y())", PartZ
End With
End Sub
NOTE THAT THE RANGE ABOVE IS JUST A PROXY WHILST I GET THE FORMULA TO WORK - SO ANY ADVICE ON HOW TO LINK THIS TO SOME SORT OF ACTIVE DATA ROW # WOULD BE AWESOME!
FRUSTRATINGLY I STILL GET THE "UNABLE TO SET THE FORMULAARRAY PROPERTY OF THE RANGE CLASS" MESSAGE.
ANY SUGGESTIONS ON IMPROVEMENT WOULD BE MUCH APPRECIATED!
THANKS,
WE2286