Sort Excel sheet by color of first column

8 vues (au cours des 30 derniers jours)
Joris
Joris le 29 Août 2011
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

Réponses (1)

Fangjun Jiang
Fangjun Jiang le 29 Août 2011
I don't think you can sort by the color directly. You have to read in the color first and then sort them.

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by