I created a function in excel and I want to use it in my VBA and I don't know
how to refer to the range
Function PD(func As String, ai As Double, Zi As String, rng As Range)
Say my range is A1:A4
How do I set rng = A1:A4
Any help
I created a function in excel and I want to use it in my VBA and I don't know
how to refer to the range
Function PD(func As String, ai As Double, Zi As String, rng As Range)
Say my range is A1:A4
How do I set rng = A1:A4
Any help
rng = Range("A1:A4")
You may need to reference the sheet as well:
rng = Sheets("mysheet").Range("A1:A4")
"Ali Baba" wrote:
> I created a function in excel and I want to use it in my VBA and I don't know
> how to refer to the range
>
> Function PD(func As String, ai As Double, Zi As String, rng As Range)
>
> Say my range is A1:A4
>
> How do I set rng = A1:A4
>
>
> Any help
>
Ali,
When you call the function from your worksheet, simply pass it the address
of the range as the fourth parameter:
=PD("Func Input",1234.56, "Zi input", A1:A4)
or they could all be range references: Excel will take them in order an
assign them to the variables:
=PD(B1,C1,D1,A1:A4)
When calling the function from VBA, you need to be a little better at
specifics:
MyValue =PD("Func Input",1234.56, "Zi input", Range("A1:A4"))
myValue=PD(Range("B1"),Range("C1"),RAnge("D1"),Range("A1:A4"))
It may also be necessary to specify which worksheet object the range object
comes from. To fully identify the range , change Range(...) to
Worksheets("Sheet name").Range("A1:A4")
HTH,
Bernie
MS Excel MVP
"Ali Baba" <AliBaba@discussions.microsoft.com> wrote in message
news:38BD6BF4-69FB-4103-83D1-F2AD4D64D136@microsoft.com...
>I created a function in excel and I want to use it in my VBA and I don't
>know
> how to refer to the range
>
> Function PD(func As String, ai As Double, Zi As String, rng As Range)
>
> Say my range is A1:A4
>
> How do I set rng = A1:A4
>
>
> Any help
>
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks