+ Reply to Thread
Results 1 to 3 of 3

Range problem

  1. #1
    Ali Baba
    Guest

    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


  2. #2
    JNW
    Guest

    RE: 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
    >


  3. #3
    Bernie Deitrick
    Guest

    Re: 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"),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
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1