+ Reply to Thread
Results 1 to 3 of 3

Group Numbers and find average

Hybrid View

aheye Group Numbers and find average 04-17-2012, 09:41 AM
PingPing Re: Group Numbers and find... 04-17-2012, 09:50 AM
111StepsAhead Re: Group Numbers and find... 04-17-2012, 10:15 AM
  1. #1
    Registered User
    Join Date
    04-17-2012
    Location
    malaysia
    MS-Off Ver
    excel 2010
    Posts
    1

    Group Numbers and find average

    Hi all.

    I have a bunch of data such as like below :

    A B
    1600 0.465479
    1600 0.46517
    1600 0.465345
    1600 0.465609
    1600 0.465238
    1600 0.46523
    1600 0.465233
    1600 0.465259
    1600 0.465573
    1600 0.465054
    1601 0.465829
    1601 0.465234
    1601 0.465543
    1601 0.465356
    1601 0.465435
    1601 0.465553
    1601 0.465236
    1601 0.465473
    1601 0.465245
    1601 0.465429
    1602 0.465726
    1602 0.466014
    1602 0.465897
    1602 0.465528
    1602 0.465673
    1602 0.465692
    1602 0.465918
    1602 0.465958
    1602 0.465756
    1602 0.465843


    how can I group those data and find the average of it.

    As column A is the group while the column B is the data.

    At the moment I just used '=Median(B1:B10)' ...but I have thousands of data.
    Note that for each group, it is in a frequency of 10 data.

    Thanks guys.

    Aheye

  2. #2
    Forum Contributor PingPing's Avatar
    Join Date
    02-19-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    158

    Re: Group Numbers and find average

    I can think of 2 possible solutions:

    1. (easier solution) use '=SUMIF()' and '=COUNTIF()'; or
    2. (better solution) use ADO and SQL.

  3. #3
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Group Numbers and find average

    
    Sub test()
        Dim x As Long
        Dim y As Long
        Dim last_Row As Long
        Dim last_Row2 As Long
        Dim temp_String As String
        Dim temp_String2 As String
        Dim sum_Total As Long
        Dim count As Long
        
        sum_Total = 0
        count = 0
        Worksheets("Main").Columns("A:A").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("D2"), Unique:=True
        last_Row = Range("A65536").End(xlUp).Row
        
        Range("D1").Value = "Unique Values"
        Range("E1").Value = "Total"
        Range("F1").Value = "Count"
        Range("G1").Value = "Average"
        
        For x = 1 To last_Row
            temp_String = Range("A" & x).Value
            temp_String2 = Range("B" & x).Value
            last_Row2 = Range("D65536").End(xlUp).Row
            For y = 2 To last_Row2
                If Range("D" & y).Value = temp_String Then
                    Range("E" & y).Value = Range("E" & y).Value + temp_String2
                    Range("F" & y).Value = Range("F" & y).Value + 1
                    Range("G" & y).Value = Range("E" & y).Value / Range("F" & y).Value
                Else
                    'do nothing
                End If
            Next y
        Next x
    End Sub
    It is probably fairly inefficient but it will do the job.
    Last edited by 111StepsAhead; 04-17-2012 at 10:24 AM.

+ 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