![]() |
Range problem
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 |
Range problem
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 |
Range problem
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"),Ran ge("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" wrote in message ... 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 |
All times are GMT +1. The time now is 07:38 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com