+ Reply to Thread
Results 1 to 5 of 5

Thread: conditional averaging macro

  1. #1
    Registered User
    Join Date
    05-02-2009
    Location
    Tehran, IRAN
    MS-Off Ver
    Excel 2007
    Posts
    12

    Lightbulb conditional averaging macro

    i have this table:
    ISO3 1999 2000 2001 2002 2003 2004 2005
    AUS 104 100 96 101 113 122 126
    AUT 103 100 100 101 104 106 106
    BEL 105 100 101 102 107 109 109
    CZE 98 100 106 119 117 118 125
    DNK 104 100 101 103 108 109 108
    FIN 105 100 100 102 107 107 105
    FRA 106 100 100 101 107 108 108
    DEU 107 100 100 101 106 108 107
    GRC 107 100 101 104 111 113 114
    HUN 99 100 107 119 122 130 133
    ISL 97 100 88 93 99 102 115
    IRL 105 100 103 109 120 123 123
    ITA 105 100 101 104 110 112 111
    JPN 95 100 89 83 84 85 79
    LUX 102 100 101 102 105 107 107
    NLD 105 100 103 107 113 114 113
    NZL 110 100 98 107 116 108 114
    NOR 102 100 103 112 111 107 111
    POL 91 100 113 108 96 96 107
    PRT 103 100 102 105 110 111 111
    ESP 102 100 102 104 109 111 113
    SWE 103 100 92 94 100 101 97
    CHE 103 100 103 106 106 106 104
    GBR 97 100 98 99 96 102 101
    USA 97 100 106 105 99 94 93
    Average

    column one containing ISO3 names of different countries. I was wondering if it's possible to have a macro that when i choosing some countries in different rows, it compute average value of them for any year in seven columns

    thanks a lot
    Last edited by aminexcel; 05-16-2009 at 04:49 PM.

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: conditional averaging macro

    A macro isn't any better or faster than a normal AutoFilter list with a "key" column to flag the countries to include. Like so... use the drop down box in the KEY cell and select "1" as the filter. Select "All" to see all countries and change your selections before filtering again.

    The averages at the bottom show the average of the visible countries, and the average of all.
    Last edited by JBeaucaire; 05-24-2009 at 07:05 PM. Reason: Sheet removed...see below for latest version
    _________________
    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
    01-25-2008
    Location
    The Netherlands
    MS-Off Ver
    2002, 2003, 2007
    Posts
    97

    Re: conditional averaging macro

    Heya,

    From what I understand from your question there is no need to create a macro to solve this issue. Simply use the SUMIF and COUNTIF functions.
    I included a sample file with a solution for you to play around with.

    I hope this is indeed what you are looking for.

    - Jeroen
    Attached Files Attached Files

  4. #4
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: conditional averaging macro

    Actually, I suppose once you've added the KEY column you don't REALLY need the autofilter, it just makes it really nice visually to use it. Once the KEY column is there, then this formula at the bottom of the chart will show the AVERAGE in realtime of the item's you have flagged:

    =SUMIF($I$2:$I$26,1,B2:B26)/COUNTIF($I$2:$I$26,1)

    ...for column B, copy that across from there.
    Attached Files Attached Files
    _________________
    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!)

  5. #5
    Registered User
    Join Date
    05-02-2009
    Location
    Tehran, IRAN
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: conditional averaging macro

    thank a lot for your attentions guys
    you solve my problem

    cheers

+ 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.2.0