write to range object using vb.net

H

herpers

Hi,

hopefully this is the right group for posting my question.

I'm writing an automation addin for excel using vb.net. One of my
function should be able to overwrite the cell values of a range object
passed as parameter to the function. Here is a small sample of the
function header:

Public Function WriteData(ByRef ResultCells As Range) As Double

I tried the following:
ResultCells.Value2(1, 1) = 42
ResultCells.Value(1, 1) = 42
ResultCells.Cells(1, 1).FormularR1C1 = 42

None of these calls work.

Does anybody know how to overwrite values of a range object? Are there
any other ways to return multiple valus from a user-defined function?

Regards,
Sascha
 
B

Bernie Deitrick

Sascha,

I'm not sure of VB.NET, but in VBA functions cannot be used to write data to ranges - the code that
does it is simply ignored. Try passing the range to a public Sub instead....

HTH,
Bernie
MS Excel MVP
 
H

herpers

Hello,
I'm not sure of VB.NET, but in VBA functions cannot be used to write datato ranges - the code that
does it is simply ignored.  Try passing the range to a public Sub instead....
it seems to be the same in vb.net. The code compiles, throws no error,
but doesn't work either. The workaround for me is to return a
Double(,)-Array. That way I can return a matrix, but the user can not
control the order and placement of the result columns. Not nice, but
it works...

Regards,

Sascha
 

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