Sort Excel sheet by color of first column

1 回表示 (過去 30 日間)
Joris
Joris 2011 年 8 月 29 日
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

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 29 日
I don't think you can sort by the color directly. You have to read in the color first and then sort them.

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by