Sorting


Posted by Matt on November 07, 2001 10:50 AM

I got a spreadsheet where everything colored in yellow is an update. Is there any way to sort a list by the fill color?



Posted by Barrie Davidson on November 07, 2001 11:07 AM

You could use a User Defined Function (UDF) like this one.

Public Function ColorNumber(Cell As Range)
Application.Volatile
ColorNumber = Cell.Interior.ColorIndex
End Function

You need to put this in to a workbook before you use it. To add it to a workbook, open the VBA editor window (ALT+F11), select the workbook you want to add it to from the Project Explorer Window. From the main menu, select Insert|Module. Paste the code in the module.

To use this function, you type it in similar to a normal Excel formula. The only difference is that you need to reference the workbook that contains the UDF. I saved it in a workbook named Book1.xls, so the formula I input was

=Book1.xls!ColorNumber(A1)

"A1" is the cell I want to determine the color number. You can then do your sort on the column containing the UDF's.

Hope I explained this well enough for you to understand.

Regards,
BarrieBarrie Davidson