+ Reply to Thread
Results 1 to 9 of 9

Finding Median using VBA code

  1. #1
    Registered User
    Join Date
    07-14-2009
    Location
    Ougadougou, Burkina Faso
    MS-Off Ver
    Excel 2003
    Posts
    27

    Finding Median using VBA code

    Hi

    I am really new to VBA programming and I have to automate an excel sheet which has the columns Closed Qtr, Apps Bucket and Res Time.
    Closed Qtr has the following entries: Q107,Q207,Q307,Q407,Q108,Q208,Q308,Q408.
    Apps Bucket has the following entries:
    BU Apps,Global Apps,Quality,others

    I have to find the median of the Res Time data based on grouping by Closed Qtr and Apps Bucket, i.e., for BU Apps in Q107, BU Apps in Q207 and so on.
    Please help me out with the VBA code for implementing this.

    Thanks

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Finding Median using VBA code

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Presumably you're giving up on your other DigDB thread ?

  3. #3
    Registered User
    Join Date
    07-14-2009
    Location
    Ougadougou, Burkina Faso
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Finding Median using VBA code

    Book2.xlsx
    I have attached this dummy workbook so that you can better understand my query.
    And yes I have given up on the DigDB query since I havent been able to make much progress on that front.

    Thanks.

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Finding Median using VBA code

    You don't provide expected results and/or where you wish to display them... the below would insert a MEDIAN array into D adjacent to each entry in A:C

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-14-2009
    Location
    Ougadougou, Burkina Faso
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Finding Median using VBA code

    Thanks DO for your prompt reply. However your code doesnt seem to be working. It is displaying only zeros in column D.
    Also my aim is to get medians for each group based on Closed Qtr and Apps Bucket. For instance, there are two BU Apps entries in Q107. I want to get the Res Time for these 2 entries and obtain the median for BU Apps in Q107. I tried using formulae like
    =if(and(a2="Q107",b2="BU Apps"),c2,"")
    for column D and then
    =median(D:D)
    for column E but it is extremely tedious if I try to do it for the data that I actually have.
    So please tell me if you can find a suitable solution to this problem.

    Thanks a lot.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Finding Median using VBA code

    The code provided, when applied to your sample file generates the following results (A:C already present, D is populated via VBA)

    Please Login or Register  to view this content.
    There is little more I can do I'm afraid.

  7. #7
    Registered User
    Join Date
    07-14-2009
    Location
    Ougadougou, Burkina Faso
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Finding Median using VBA code

    Yeah you are right. I must have missed something the first time. Thanks for your help. Appreciate it.

  8. #8
    Forum Contributor
    Join Date
    07-11-2010
    Location
    Minneapolis, USA
    MS-Off Ver
    Excel 2016
    Posts
    308

    Re: Finding Median using VBA code

    Hello DonkeyOte,

    I realize this post is old but your code is very helpful.

    I was wondering if it can be altered to group on more then the two fields in use.

    I have 5 fields I need to group on, and your code is exactly what I an in need of.

    Thanks

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Finding Median using VBA code

    Welcome to the forum, capson.

    Please take a few minutes to read the forum rules, and then start your own thread.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

+ 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