Ilias
Ilias

Reputation: 3

Input a UDF formula in a range with VBA

I have the UDF Test(rng as range) and I want to do something like this:

Dim rng2 as Range
Set rng2 = blah blah
rng2.formula = "=test(rng)"

How can I do this?

Upvotes: 0

Views: 164

Answers (3)

SierraOscar
SierraOscar

Reputation: 17637

What if rng is on another sheet? Then you need this:

rng2.Formula = "=test('" & rng.Parent.Name & "'!" & rng.Address & ")"

Upvotes: 1

Skullnick
Skullnick

Reputation: 13

You have to specify the address of range i.e :

rng2.formula = "=test(" & rng.address & ")"

Upvotes: 0

Matteo NNZ
Matteo NNZ

Reputation: 12645

The range address must be passed as a variable, not a string:

Dim rng2 as Range
Set rng2 = blah blah
rng2.formula = "=test(" & rng.Address & ")"

Upvotes: 1

Related Questions