FREE Excel STUFF
SearchSearch Excel Content
Excel Help. Popular
NEW! Multiple Excel Search & Links
Excel Formulas
Excel Macros
Excel Newsletter
PRODUCTS
Up to $139.00 FREE!
Categories & SearchSearch for software
Excel Templates
Excel Add-ins
Excel Training
More....
OTHER
Excel Development


Sort by Color In Excel


NEW! More Books..
Add to Google advanced search! Free Help!

Add Excel Answers & Search To Your Google Toolbar Details

Current Special! Complete Excel Excel Training Course for Excel 97 - Excel 2003, only $145.00. $59.95 Instant Buy/Download, 30 Day Money Back Guarantee & Free Excel Help for LIFE!

Back to: Excel Custom Function/Formulas . Got any Excel/VBA Questions? Free Excel Help

This UDF (User Defined Function) will allow you to nominate a range of colored cells to be sorted by the color order chosen. In other words, Sort by color! This example code sorts by the cells Interior (Background) color. You can also sort by the cells Text color by Replacing Interior with Font.

The Code

Function ColorRank(ColorOrder As Range, LookCell As Range)
'''''''''''''''''''''''''''''''''''''''''''''
'Written by OzGrid Business Applications
'www.ozgid.com

'Ranks a list of Colors so they can be sorted
'''''''''''''''''''''''''''''''''''''''''''''

	Dim i As Integer
	Dim ICol1 As Integer
	Dim ICol2 As Integer

	i = 1
	ICol2 = -1
	ColorRank = 0

	'Loop until match is found
	Do Until ICol1 = ICol2
		'Replace "Interior" with Font to sort by Font color
		ICol1 = ColorOrder(i, 1).Interior.ColorIndex
		ICol2 = LookCell.Interior.ColorIndex
			If i = ColorOrder.Rows.Count + 1 Then
				'No Match found place in Text
				ColorRank = "No colour match!!!"
				Exit Do
			End If
		'Pass the Row number of the colour match
		ColorRank = i
		i = i + 1
	Loop
End Function

To use this UDF push Alt+F11 and go Insert>Module and paste in the code. Push Alt+Q and save. The Function will appear under "User Defined" in the Paste Function (Shift+F3).

Use the Function as shown in the graphic example below.

Color Order   Amount Formula Result Formula Used
  200 4 =ColorRank($A$2:$A$7,C2)
  100 6 =ColorRank($A$2:$A$7,C3)
  955 2 =ColorRank($A$2:$A$7,C4)
  500 3 =ColorRank($A$2:$A$7,C5)
  1000 1 =ColorRank($A$2:$A$7,C6)
  800 2 =ColorRank($A$2:$A$7,C7)
  1500 1 =ColorRank($A$2:$A$7,C8)
  500 3 =ColorRank($A$2:$A$7,C9)
  2000 1 =ColorRank($A$2:$A$7,C10)
  100 5 =ColorRank($A$2:$A$7,C11)
  20 No Color match !! =ColorRank($A$2:$A$7,C12)

$A$2:$A$7is the Color Order wanted.

Once you have the formulas in, reading from your list and from the "Color Order" list you simply sort your list and the formula results by the "Formula Result" column.

Excel Dashboard Reports & Excel Dashboard Charts 50% Off

Special! Free Choice of Complete Excel Training Course OR Excel Add-ins Collection on all purchases totaling over $64.00. ALL purchases totaling over $150.00 gets you BOTH! Purchases MUST be made via this site. Send payment proof to special@ozgrid.com 31 days after purchase date.


Instant Download and Money Back Guarantee on Most Software

Excel Trader Package Technical Analysis in Excel With $139.00 of FREE software!

Add to Google Search Tips FREE Excel Help

Microsoft ® and Microsoft Excel ® are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft