+ Reply to Thread
Results 1 to 5 of 5

Macro to calculate median of all data within a given year

  1. #1
    Registered User
    Join Date
    05-29-2012
    Location
    Fayetteville, AR
    MS-Off Ver
    Excel 2010
    Posts
    12

    Macro to calculate median of all data within a given year

    Hello,

    I have a macro that goes through all my data in Col A (which are dates in m/d/yyyy) and then inserts a row before all the data points whenever the year changes.....for a summary of the data

    When the new year is inserted above the data points I want the adjacent cell to calculate the median for that specific year. Each row is a different parameter and will need to calculate the median for that specific year.

    Here is my code so far.
    Please Login or Register  to view this content.
    File is attached if you have any questions.

    Thanks in advance!
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to calculate median of all data within a given year

    An array formula take care of this for you. Enter this formula into B11, then confirm it by pressing CTRL-SHIFT-ENTER:

    =IF(B$5>0, MEDIAN(IF(YEAR($A$26:$A$45)=$A11, B$26:B$45)), "")

    You will know the the array is active by the curly braces { } that appear around your formula.

    Then copy that to the right, then down to the other rows with years listed in column A.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    05-29-2012
    Location
    Fayetteville, AR
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Macro to calculate median of all data within a given year

    Thanks for the quick reply! However I am getting Values that are a little off than what they should be. I'll keep trying though. Thanks again!
    Last edited by cameron.beyers; 08-16-2012 at 12:02 PM.

  4. #4
    Registered User
    Join Date
    05-29-2012
    Location
    Fayetteville, AR
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Macro to calculate median of all data within a given year

    The formula is treating all blank cells as zeros.....I can't delete these rows. Is there any way that the formula can ignore the blank cells??

    ---------- Post added at 12:50 PM ---------- Previous post was at 12:42 PM ----------

    I figured it out. In order to ignore blank cells the formula should read.
    =IF(C$5>0,MEDIAN(IF(YEAR($A$26:$A$45)=$A16,IF(C26:C45<>"",C$26:C$45))),"")

    then the Ctrl+Shift+Enter for array.

    Thanks a ton! This will save me lots of time!

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to calculate median of all data within a given year

    Glad you go it. Good job.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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