Hi,
I have been using the Application.WorksheetFunction.Large to find the top 10 numbers in a range but I cannot seem to get the rest of the code to find the corresponding row number when there are duplicate values. My code so far is as below:
The values in the range are not in ascending/descending order and there will always be duplicates. The Large function does find all the top 10 values, including duplicates, but it is just the row function that needs tweaking.
For reference I will be using the row number to lookup the corresponding ID number to the top 10 value in another column and plot it on a heat map. The message box is just a little test to see if the values are being picked up correctly.
Many thanks!!!
I have been using the Application.WorksheetFunction.Large to find the top 10 numbers in a range but I cannot seem to get the rest of the code to find the corresponding row number when there are duplicate values. My code so far is as below:
Code:
Sub Top10Values()
Dim rngTestArea As Range, k As Integer, j As Long, MyResult As String, rowcount As Long, lastrow as long
Dim report As Worksheet, register As Worksheet
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Set report = Worksheets("REPORT")
Set register = Worksheets("Register")
lastrow = register.Cells(Rows.Count, 17).End(xlUp).Row
Set rngTestArea = register.Range("Q2:Q" & lastrow)
j = 0
For k = 1 To 10
j = Application.WorksheetFunction.Large(rngTestArea, k)
If j > 0 Then
rowcount = register.Columns(17).Find(what:=j, after:=Cells(7, 17), LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows).Row
MyResult = MyResult & "Rank " & k & " is " & j & " in row " & rowcount & vbCr
End If
Next k
MsgBox MyResult
End Sub
The values in the range are not in ascending/descending order and there will always be duplicates. The Large function does find all the top 10 values, including duplicates, but it is just the row function that needs tweaking.
For reference I will be using the row number to lookup the corresponding ID number to the top 10 value in another column and plot it on a heat map. The message box is just a little test to see if the values are being picked up correctly.
Many thanks!!!