+ Reply to Thread
Results 1 to 3 of 3

Excel formula to VBA, use of range such as MEDIAN(1,2,start:end)

  1. #1
    Registered User
    Join Date
    06-25-2012
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    22

    Excel formula to VBA, use of range such as MEDIAN(1,2,start:end)

    Hi there,

    I have an Excel formula which I wish to use in VBA.

    I have learned that MOD(x,y) becomes x MOD y but I am having problem with the following:

    =MEDIAN(value1, value2, startplace:endplace)

    The problem is the startday:endday. Even though I have set up the variabled in VBA to replaced the named cells from Excel worksheet, VBA doesn't like the syntax.

    Eg, in Excel, startplace =3 and endplace=5 the result is 3 (median of 1, 2, 3, 4, 5)

    In VBA:
    The line in in red as an error.

    Any ideas how to incorporate the startplace:endplace ?

    Thanks

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Excel formula to VBA, use of range such as MEDIAN(1,2,start:end)

    Post the code.
    Hint:
    Range("A1").Value = WorksheetFunction.Median(112, 222, Range("D1:D10").Value)
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    06-25-2012
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Excel formula to VBA, use of range such as MEDIAN(1,2,start:end)

    Thank you for your suggestion protonleah, but actually your example would include the values of the cells in the range D1 to D10.

    Sorry I wasn't clear but startplace and endplace are values (not references).

    If you see my example, startplace has a VALUE of 3 and endplace a VALUE of 5.

    The VBA is along these lines:

    Please Login or Register  to view this content.
    which means the code actually executes:
    medianvalue = median(1,2,3,4,5)

    But I get an error on the startplace:endplace.

    So its a range but not an Excel rage, if that makes sense!
    Last edited by Cutter; 10-29-2012 at 04:05 PM. Reason: Added code tags

+ 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