macro to extract 10 highest values from 1 column onto new sheet

bluefish44

Board Regular
Joined
Apr 3, 2009
Messages
190
Thanks in advance.....

I have a tab called 'Medium rollup'. On this tab, starting in cell F4 going down I have a set of values. I'd like to create a macro where it will find the10 highest values from this column and then paste the entire rows that contain these values on a sheet called 'Top 10' starting in row 2. My VBA isn't up to snuff to get this done. Ideas?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Code:
Sub getHigh10()
Dim lRow As Long
lRow = Sheets("Medium Rollup").Range("F" & Rows.Count).End(xlUp).Row
Sheets("Top 10").Range("A2:A11").Value = Evaluate("transpose(LARGE('Medium Rollup'!F4:F" & lRow & ",{1,2,3,4,5,6,7,8,9,10}))")
End Sub
 
Upvote 0
Thanks VBA Geek - This correctly pastes the 10 highest values in column A, but instead are you able to alter the code to paste the entire rows that contain these values?
 
Upvote 0
Code:
Sub hi()
Dim lRow As Long
lRow = Sheets("Medium Rollup").Range("F" & Rows.Count).End(xlUp).Row
Range(Join(Filter(Evaluate(Replace("=IF(TRANSPOSE($F$4:$F$#)>=LARGE($F$4:$F$2#,10),TRANSPOSE(ADDRESS(ROW($F$4:$F$#),6,,,""Medium Rollup"")),""@@"")", "#", lRow)), "@@", 0), ",")).EntireRow.Copy _
        Sheets("Top 10").Range("A2")


End Sub
 
Upvote 0
gorgeous! - 1 last request. The first code you gave ordered the numbers in descending order on the 'top 10' sheet. Your new code pastes all of the rows correctly, except it now orders them alphabetically by column A. Instead, I would like them to continue to be ordered by column F in descending order (Largest on top).
 
Upvote 0
This code is exactly what I need for my app. The first section of code runs fine on my data, the second, which copies the entire row returns a "Run-Time Error 13, type mismatch". I've also tried the code on a data set of only numbers and get the same error. I've researched the error but have not discovered a resolution. Running Windows 8 and Excel 2013. I'm well versed in excel but not VB. Below is a small segment of my data, any help will be appreciated:

[TABLE="width: 382"]
<colgroup><col><col span="2"><col span="2"></colgroup><tbody>[TR]
[TD][TABLE="width: 382"]
<colgroup><col><col span="2"><col span="2"></colgroup><tbody>[TR]
[TD]Left Jab[/TD]
[TD]326[/TD]
[TD]20.5[/TD]
[TD]2015-08-14[/TD]
[TD]11:23:35:177[/TD]
[/TR]
[TR]
[TD]Right Hook[/TD]
[TD]441[/TD]
[TD]11.8[/TD]
[TD]2015-08-14[/TD]
[TD]11:23:35:425[/TD]
[/TR]
[TR]
[TD]Left Hook[/TD]
[TD]426[/TD]
[TD]16.8[/TD]
[TD]2015-08-14[/TD]
[TD]11:23:38:063[/TD]
[/TR]
[TR]
[TD]Left Hook[/TD]
[TD]440[/TD]
[TD]16.5[/TD]
[TD]2015-08-14[/TD]
[TD]11:23:38:357[/TD]
[/TR]
[TR]
[TD]Left Hook[/TD]
[TD]524[/TD]
[TD]16.3[/TD]
[TD]2015-08-14[/TD]
[TD]11:23:38:729[/TD]
[/TR]
[TR]
[TD]Left Jab[/TD]
[TD]352[/TD]
[TD]18.8[/TD]
[TD]2015-08-14[/TD]
[TD]11:23:41:751[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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