Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Diane
 
Posts: n/a
Default How can I sort a spreadsheet of data by colour?

I have 4 colours on my spreadsheet, how do I sort the data by the colour?
  #2   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default How can I sort a spreadsheet of data by colour?

See http://www.xldynamic.com/source/xld....r.html#sorting for a
working solution

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Diane" wrote in message
...
I have 4 colours on my spreadsheet, how do I sort the data by the colour?



  #3   Report Post  
Junior Member
 
Location: Maine, USA
Posts: 8
Send a message via Yahoo to mainemike
Default

Diane,

Try this...

Function ColorIndexOfCell(Rng As Range, _
Optional OfText As Boolean, _
Optional DefaultAsIndex As Boolean = True) As Integer
Dim C As Long
If OfText = True Then
C = Rng.Font.ColorIndex
Else
C = Rng.Interior.ColorIndex
End If
If (C < 0) And (DefaultAsIndex = True) Then
If OfText = True Then
C = GetBlack(Rng.Worksheet.Parent)
Else
C = GetWhite(Rng.Worksheet.Parent)
End If
End If
ColorIndexOfCell = C
End Function
Function GetWhite(WB As Workbook) As Long
Dim Ndx As Long
For Ndx = 1 To 56
If WB.Colors(Ndx) = &HFFFFFF Then
GetWhite = Ndx
Exit Function
End If
Next Ndx
GetWhite = 0
End Function
Function GetBlack(WB As Workbook) As Long
Dim Ndx As Long
For Ndx = 1 To 56
If WB.Colors(Ndx) = 0& Then
GetBlack = Ndx
Exit Function
End If
Next Ndx
GetBlack = 0
End Function

Then, in the newly created column, enter either of the following formulas:

If you want to sort by the Background color of the cell, use the formula
=ColorIndexOfCell(A1,FALSE,TRUE)

If you want to sort by the Font color of the cell, use the formula
=ColorIndexOfCell(A1,TRUE,TRUE)

Of course, you can add your other two colors to this and substitute white/black with the ones you want. Just be sure to use the ColorIndex values to get the colors you want.

If you don't want to do VBA and it's just a once in awhile thing, you can check out this link to sort your worksheet by using the menus..

http://www.digdb.com/excel_add_ins/s...ngth_color/#A3

Hope that helps.

Mike

Quote:
Originally Posted by Diane
I have 4 colours on my spreadsheet, how do I sort the data by the colour?
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
how do I set up a excel spreadsheet to auto sort data in order jason Excel Discussion (Misc queries) 0 January 3rd 06 07:17 PM
Excel Macro to Copy & Paste [email protected] Excel Worksheet Functions 0 December 1st 05 01:56 PM
Can I sort excel spreadsheet data by fill color of cells? Fashionheadhunter Excel Discussion (Misc queries) 2 September 7th 05 01:35 AM
Pulling data from 1 sheet to another Dave1155 Excel Worksheet Functions 1 January 12th 05 05:55 PM
Importing Data From Another Spreadsheet Tiziano Excel Discussion (Misc queries) 6 January 7th 05 02:35 AM


All times are GMT +1. The time now is 03:04 AM.

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

About Us

"It's about Microsoft Excel"