Accessing separate worksheets while in FormulaArray function

legacy30

New Member
Joined
Jun 7, 2012
Messages
1
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:

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!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,207,421
Messages
6,078,436
Members
446,337
Latest member
nrijkers

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top