Sort Excel sheet by color of first column

I want to sort the sheet by the color of the first column. I got so far to sort alphabetically, but the last step to sort by color is what im missing.
To sort by name:
fname = 'C:\Matlab\test.XLS';
% Open an Excel Server
Excel = actxserver('Excel.Application');
Excel.Visible = 1;
% get Workbooks interface and invoke Open method
Excel.Workbooks.Open(fname);
Excel.Sheets.Item('Module A').Activate;
range = Excel.ActiveSheet.Range('A1:C5')
invoke(range, 'Sort', Excel.ActiveSheet.Range('A1:A5'), 1)
Maybe of help, the recorded macro to sort by color:
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Add Key:=Range("A1:A5") _
, SortOn:=xlSortOnCellColor, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Tabelle1").Sort
.SetRange Range("A1:C5")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Answers (1)

I don't think you can sort by the color directly. You have to read in the color first and then sort them.

Categories

Asked:

on 29 Aug 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!