Sort Excel sheet by color of first column
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!