LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Finding and Formatting the 5 highest values in a range?

Whilst these replies have flooded in I thought I might turn my novice
hand to the problem and came up with the following, much messier
solution for what it's worth...

It assumes that you have 20 numbers in cells A1:A20 on a sheet called
"Sheet1".

Option Explicit

Private Sub CommandButton1_Click()
Dim i As Integer
Dim theRange As Range
i = 1
Set theRange = Sheets("Sheet1").Range("A1:A20")
'Takes any existing colour formats away
theRange.Select
Selection.Interior.ColorIndex = xlNone

With Application.WorksheetFunction

'loop to check each number in the range with the RANK function and
colour accordingly

While i < 20
If .Rank(Cells(i, 1).Value, theRange, 0) = 1 Then
Cells(i, 1).Interior.ColorIndex = 3
End If

If .Rank(Cells(i, 1).Value, theRange, 0) = 2 Then
Cells(i, 1).Interior.ColorIndex = 6
End If

If .Rank(Cells(i, 1).Value, theRange, 0) = 3 Then
Cells(i, 1).Interior.ColorIndex = 5
End If

If .Rank(Cells(i, 1).Value, theRange, 0) = 4 Then
Cells(i, 1).Interior.ColorIndex = 16
End If

If .Rank(Cells(i, 1).Value, theRange, 0) = 5 Then
Cells(i, 1).Interior.ColorIndex = 10
End If

i = i + 1
Wend
End With

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
finding is a value is betwen a range of values Alberto Ast[_2_] Excel Discussion (Misc queries) 5 September 12th 09 05:31 PM
Finding highest values Hoytmedic Excel Worksheet Functions 3 July 4th 07 08:58 PM
Finding the highest values bob135 Excel Discussion (Misc queries) 7 April 12th 06 08:22 AM
Finding (Multiple) Highest Values in Column Shay Hurley Excel Worksheet Functions 1 October 3rd 05 04:19 PM
3 highest values indicated using formatting John Excel Worksheet Functions 7 May 15th 05 02:26 PM


All times are GMT +1. The time now is 12:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"