Formula to find out the top value from a list

Goddess

Board Regular
Joined
Dec 3, 2015
Messages
94
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I have 3 sheets of data. Sheet 1 is the raw data. Sheet 2 is where I calculate the 'mean'.

Sheet 3 is where I need to present the data. I will need to extract the top 5 'mean' from Sheet 2. Is there any formula to calculate it and return the corresponding text, with the same cell colours?

Copy of 01 Response Summary GC.xlsx
ABCDEFGHIJKLMNOPQ
1Sheet1
2AnnaBenJim
3Mean2468Total2468Total2468Total
4FruitsApple340076100732106
5FruitsGrape223075200740206
6FruitsOrange142073400740206
7VegetablesCarrot151071510713116
8VegetablesLeek123171231742006
9VegetablesSpinach520075200742006
10VegetablesCucumber430074300721216
11MeatLamb142074010541106
12MeatChicken430073110560006
13
14Sheet2
15AnnaBenJim
16Mean2468Total2468Total2468Total
17FruitsApple616003.14124002.2968603.33
18FruitsGrape481804.29108002.57801203.33
19FruitsOrange2161204.29616003.14801203.33
20VegetablesCarrot220604.00220604.00212684.67
21VegetablesLeek281885.14281885.1488002.67
22VegetablesSpinach108002.57108002.5788002.67
23VegetablesCucumber812002.86812002.86441284.67
24MeatLamb2161204.2980602.8084603.00
25MeatChicken812002.8664603.20120002.00
26
27Sheet3
28Top 5 items
29AnnaBenJim
30LeekLeekCarrot
31GrapeCarrotCucumber
32OrangeChickenApple
33LambOrangeGrape
34CarrotLambOrange
35
Sheet1
Cell Formulas
RangeFormula
Q4:Q12,L4:L12,G4:G12G4=SUM(C4:F4)
M17:P25,H17:K25,C17:F25C17=C4*C$3
G17:G25,Q17:Q25,L17:L25G17=SUM(C17:F17)/G4


Thanks!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

VBA Code:
Option Explicit
Sub TEST()
Dim lr&, i&, j&, k&, c&, rng, arr(1 To 6, 1 To 6)
Application.ScreenUpdating = False
With Sheets("Sheet2")
    lr = .Cells(Rows.Count, "B").End(xlUp).Row
    rng = .Range("B4:Q" & lr).Value
    .Range("WW4:WW" & lr).Value = Evaluate("=ROW(A1:a" & lr - 3 & ")")
    For j = 7 To 17 Step 5
        c = c + 1
        .Range("a4:WW" & lr).Sort Cells(3, j), xlDescending
        arr(1, c) = .Cells(2, j - 4).Value
        For k = 2 To 6
            arr(k, c) = .Cells(k + 2, 2).Value
            arr(k, c + 3) = .Cells(k + 2, 2).Interior.Color
        Next
    Next
    .Range("a4:WW" & lr).Sort Cells(3, "WW"), xlAscending
    .Columns("WW").ClearContents
End With
Sheets.Add after:=Sheets(Sheets.Count)
With ActiveSheet
    .Range("A3").Resize(6, 3).Value = arr
    For i = 2 To 6
        For j = 1 To 3
            .Cells(i + 2, j).Interior.Color = arr(i, j + 3)
        Next
    Next
End With
Application.ScreenUpdating = True
End Sub

With sheet2 data display like this:
Book1
ABCDEFGHIJKLMNOPQ
1Sheet2
2AnnaBenJim
3Mean2468Total2468Total2468Total
4FruitsApple616003.142857124002.28571468603.333333
5FruitsGrape481804.285714108002.571429801203.333333
6FruitsOrange2161204.285714616003.142857801203.333333
7VegetablesCarrot220604220604212684.666667
8VegetablesLeek281885.142857281885.14285788002.666667
9VegetablesSpinach108002.571429108002.57142988002.666667
10VegetablesCucumber812002.857143812002.857143441284.666667
11MeatLamb2161204.28571480602.884603
12MeatChicken812002.85714364603.2120002
Sheet2
 
Upvote 0
Hi, thanks! Hmmm... I'm not good in VBA at all 😅

Will give it a try and see how it goes.
 
Upvote 0

Forum statistics

Threads
1,214,790
Messages
6,121,608
Members
449,038
Latest member
apwr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top