Automation add-in - UDF to multi cells...

D

dale purdon

Hi all,

I have been doing some reading on this forum and could not find exactly
what i was looking for so i decided to post. I have an automation add-in
written in C#. I need a UDF function to populate multiple cells with
data. (like a table of data, and the cell containing the UDF function
would be the top left corner of the 'rendered' table).

Is this possible?

I have read that a UDF function can only return and populate a single
cell. Well there must be some way to do it as I have seen other add-ins
do this, and im trying to replicate the behaviour.

Thanks!

Dale

*** Sent via Developersdex http://www.developersdex.com ***
 
D

Dave Peterson

A UDF can only return something to the range that holds that UDF.

But if you select the range (say A1:B4) and array enter your formula (using
ctrl-shift-enter), then all 8 of these cells could be populated by that single
array formula in multiple cells.

I don't speak the C#, but in VBA, I'd use this kind of thing:

Option Explicit
Function myFunct() As Variant
Dim myArr(1 To 4, 1 To 2) As Variant
Dim rCtr As Long
Dim cCtr As Long

For rCtr = LBound(myArr, 1) To UBound(myArr, 1)
For cCtr = LBound(myArr, 2) To UBound(myArr, 2)
myArr(rCtr, cCtr) = "R" & rCtr & "--" & "C" & cCtr
Next cCtr
Next rCtr

myFunct = myArr

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top