Greetings,
I am trying to print arrays out to separate worksheets while running a FormulaArray function. I'm not getting any compile or run-time errors. For some reason, though, the function seems to "give up" when I try to select or activate a separate sheet (outside of the sheet that contains the original selection's FormulaArray).
Here's basically what I have:
...so I'm passing two ranges to the function by relative reference to the current selection. Then in the function (in a separate module) I am creating multiple 2-D arrays given these inputs. What I want to do is monitor the construction of those 2-D arrays in separate worksheets, by outputing the array to a range in the separate worksheets as I iterate through the construction of the arrays.
For the sake of argument, let's say I was creating an array from one of the ranges being passed to the function:
...with the third line being the attempt to output the new array to a range in a separate worksheet.
I've tried putting this logic (i.e. copy Range to Array, output Array to Range) into it's own Sub that I can call from the Function, as well as keeping it in the Function as illustrated above. I've also tried to use every Activate and/or Select sequence that I can think of, even going back and re-selecting the original FormulaArray range "Q10:X70" prior to exitting the Sub and returning to the Function.
What seems to happen is that every time the code encounters this logic, it bails on MyFunction and just returns to Macro1.
Any help with this would be greatly appreciated!
I am trying to print arrays out to separate worksheets while running a FormulaArray function. I'm not getting any compile or run-time errors. For some reason, though, the function seems to "give up" when I try to select or activate a separate sheet (outside of the sheet that contains the original selection's FormulaArray).
Here's basically what I have:
Code:
Sub Macro1
Range("Q10:X70").Select
Selection.FormulaArray = "=MyFunction(R[-5]C[-8]:R[-5],C[-3],'Sheet2'!R[5]C[5]:R[20]C[20])"
Selection.Copy
Range("Q10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub
...so I'm passing two ranges to the function by relative reference to the current selection. Then in the function (in a separate module) I am creating multiple 2-D arrays given these inputs. What I want to do is monitor the construction of those 2-D arrays in separate worksheets, by outputing the array to a range in the separate worksheets as I iterate through the construction of the arrays.
For the sake of argument, let's say I was creating an array from one of the ranges being passed to the function:
Code:
Function MyFunction(DB1 as Range, DB2 as Range)
.
.
.
Dim MyArray as Variant
MyArray = Range("DB1").Value
Sheets("Sheet3").Range("A2").Resize(UBound(MyArray,1), UBound(MyArray,2)).Value = MyArray
.
.
.
End Function
...with the third line being the attempt to output the new array to a range in a separate worksheet.
I've tried putting this logic (i.e. copy Range to Array, output Array to Range) into it's own Sub that I can call from the Function, as well as keeping it in the Function as illustrated above. I've also tried to use every Activate and/or Select sequence that I can think of, even going back and re-selecting the original FormulaArray range "Q10:X70" prior to exitting the Sub and returning to the Function.
What seems to happen is that every time the code encounters this logic, it bails on MyFunction and just returns to Macro1.
Any help with this would be greatly appreciated!