How do you sort by Cell Color in Excel using Powershell?

时间:2016-04-04 18:59:01

标签: excel powershell

Currently this works, but I need the SortOnCellColor to be by RGB(255,199,206).

$range2 = $ExcelWorkSheet.range("D2")
$range3 = $ExcelWorkSheet.range("E2")

#two-column sort
$ExcelWorkSheet.sort.sortFields.clear()
[void]$ExcelWorkSheet.sort.sortFields.add($range2, $xlSortOnCellColor, $xlAscending,2,1)
[void]$ExcelWorkSheet.sort.sortFields.add($range3, $xlSortOnValues, $xlAscending,`
$xlSortNormal)

$ExcelWorkSheet.sort.setRange($range1)
$ExcelWorkSheet.sort.header = $xlYes
$ExcelWorkSheet.sort.orientation = $xlTopToBottom 
$ExcelWorkSheet.sort.apply()

This is how you do it in VBA:

ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add(Range("B1:B25"), _ 
 xlSortOnFontColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255,199,206) 

This is what the sort looks like

This is what it needs to look like

0 个答案:

没有答案
相关问题