在Mac中,阅读Excel中有多less单元格具有某种颜色

我正在使用Office 2011 for Mac,在Excel应用程序中,是否有可能以某种方式读取一行中有多less个单元格是红色的?

这是一个AppleScript,它返回具有红色填充的单元格的列和行数。 或者你正在寻找除AppleScript以外的其他语言?

tell application "Microsoft Excel" tell active sheet set lastColumn to used range's last column's first column index set lastRow to used range's last row's first row index set redCells to {} repeat with columnCounter from 1 to lastColumn repeat with rowCounter from 1 to lastRow if column columnCounter's row rowCounter's interior object's color is {255, 0, 0} then copy {columnCounter, rowCounter} to end of redCells end if end repeat end repeat return redCells end tell end tell 

我敢打赌,像tell application "Microsoft Excel" to tell active sheet to return every cell of used range whose interior object's color is {255, 0, 0}的单行脚本tell application "Microsoft Excel" to tell active sheet to return every cell of used range whose interior object's color is {255, 0, 0}将运行得更快,但我无法弄清楚确切的措辞。

使用下面的代码可以使用VBA。 把它放在一个模块中,并从你想检查的表中运行。

 Sub GetRedCells() Dim rCell As Range, rRowRange As Range, iRow As Integer, iInteriorColour As Integer, iFontColour As Integer iRow = Application.InputBox("Enter Row Number") If iRow > 0 Then Set rRowRange = ActiveSheet.Range(ActiveSheet.Cells(iRow, "A"), ActiveSheet.Cells(iRow, ActiveSheet.UsedRange.Columns.Count)) For Each rCell In rRowRange If rCell.Interior.Color = vbRed Then iInteriorColour = iInteriorColour + 1 If rCell.Font.Color = vbRed Then iFontColour = iFontColour + 1 Next rCell MsgBox "You have " & iInteriorColour & " cell(s) that have a red interior " & vbCr & "and " & iFontColour & " cell(s) with a red font." End If End Sub