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



Hey all,


I am trying to figure out a way to format a set of number so that the
number with the max value has a cell color of red, the next max value
has a cell color of yellow, the 3rd max value has a cell color of blue,
the 4th max value has a cell color of green, and the 5th max value has
a cell color of grey. If this is confusing replace the "max value" with
"top scoring". There will not be any ties.


For example

02
23 (yellow)
05
27 (red)
08
19 (blue)
01
10 (grey)
00
14 (green)
06


Has anyone done something similar to this?

Lance


--

Lance Hoffmeyer


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Finding and Formatting the 5 highest values in a range?

Hi Lance,

Something like this may work for you:

Sub ColorFinishers()
Dim rng As Range
Dim nPlace As Integer

Selection.Interior.ColorIndex = xlColorIndexNone

For Each rng In Selection
For nPlace = 1 To 5
If Application.WorksheetFunction.Large(Selection, nPlace) =
rng.Value Then
'/ color appropriately
Select Case nPlace
Case 1
rng.Interior.Color = vbRed
Case 2
rng.Interior.Color = vbYellow
Case 3
rng.Interior.Color = vbBlue
Case 4
rng.Interior.Color = vbGreen
Case 5
rng.Interior.Color = vbBlack
End Select
End If
Next nPlace
Next rng
End Sub

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]

Lance Hoffmeyer wrote:
Hey all,


I am trying to figure out a way to format a set of number so that the
number with the max value has a cell color of red, the next max value
has a cell color of yellow, the 3rd max value has a cell color of
blue, the 4th max value has a cell color of green, and the 5th max
value has a cell color of grey. If this is confusing replace the
"max value" with "top scoring". There will not be any ties.


For example

02
23 (yellow)
05
27 (red)
08
19 (blue)
01
10 (grey)
00
14 (green)
06


Has anyone done something similar to this?

Lance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Finding and Formatting the 5 highest values in a range?

Sub Test()
Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
Select Case True
Case Cells(i, "A").Value = Application.Large(Range("A:A"), 1)
Cells(i, "A").Interior.ColorIndex = 3
Case Cells(i, "A").Value = Application.Large(Range("A:A"), 2)
Cells(i, "A").Interior.ColorIndex = 6
Case Cells(i, "A").Value = Application.Large(Range("A:A"), 3)
Cells(i, "A").Interior.ColorIndex = 5
Case Cells(i, "A").Value = Application.Large(Range("A:A"), 4)
Cells(i, "A").Interior.ColorIndex = 10
Case Cells(i, "A").Value = Application.Large(Range("A:A"), 5)
Cells(i, "A").Interior.ColorIndex = 16
End Select
Next i

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Lance Hoffmeyer" wrote in message
...


Hey all,


I am trying to figure out a way to format a set of number so that the
number with the max value has a cell color of red, the next max value
has a cell color of yellow, the 3rd max value has a cell color of blue,
the 4th max value has a cell color of green, and the 5th max value has
a cell color of grey. If this is confusing replace the "max value" with
"top scoring". There will not be any ties.


For example

02
23 (yellow)
05
27 (red)
08
19 (blue)
01
10 (grey)
00
14 (green)
06


Has anyone done something similar to this?

Lance


--

Lance Hoffmeyer




  #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

Reply
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:48 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"