+ Reply to Thread
Results 1 to 5 of 5

VBA Macro to Calculate Average excluding Duplicates

  1. #1
    Registered User
    Join Date
    05-02-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    22

    VBA Macro to Calculate Average excluding Duplicates

    Hi,

    I am trying to calculate the average value for all items in each quater but there are a lot of duplicate items that I do not want their values be double counted in the average calculation. I could simply filter duplicates and get the regular average, but I cannot do that everytime for a lot of data. Therefore, I need a VBA Macro (guessing a loop one) that averages the "Quarter Values" column for all IDs if those IDs are not a repeat. (its okay for the values to be repeat because different IDs could possibly have same values). I also need the average only count for and sum positive numbers, not zero or negatives or texts. The last row is variant.

    I would need the Macro be linked to the 'Calculate Button' on the Average Sheet.

    test.xlsx

    Thanks a lot

  2. #2
    Registered User
    Join Date
    12-04-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: VBA Macro to Calculate Average excluding Duplicates

    what if some of the data has the same ID but different value?

  3. #3
    Registered User
    Join Date
    05-02-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: VBA Macro to Calculate Average excluding Duplicates

    good point to bring up. In my case all the ID #s are unique. and each unique ID has the same value.

  4. #4
    Registered User
    Join Date
    05-02-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: VBA Macro to Calculate Average excluding Duplicates

    I am not sure if what I said makes sense, but for example, ID # 444 will always have the value 8 even if repeated multiple times.

  5. #5
    Registered User
    Join Date
    12-04-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: VBA Macro to Calculate Average excluding Duplicates

    i guess writing a vba will take more times.. what if we use simple excel formula.. all you need is adding 4 columns to each quarter..

    see my attachment..


    test.xlsx


    =================================
    visit my blog!
    Last edited by hanxlsx; 12-04-2012 at 06:24 PM.

  6. #6
    Registered User
    Join Date
    05-02-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: VBA Macro to Calculate Average excluding Duplicates

    How about This instead:

    a Macro that would
    1) Copy and Paste the two columns in a new sheet
    2) Removes the duplicate ID rows from the data in the new sheet
    3) Calculates the regular average based on the data remained in the new sheet
    4) Copy pastes the calculated average in a cell in the Main worksheet
    5) Deletes the temporary new sheet used to do all the dirty work

    preferably all this hidden behind the scenes?

+ 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