我在 Excel 应用程序中使用 Office 2011 for Mac,是否有可能以某种方式读取一行中有多少个单元格是红色的?
问问题
2324 次
2 回答
1
这是一个 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}
会运行得更快,但我无法弄清楚确切的措辞。
于 2013-02-02T19:32:55.273 回答
1
这可以使用带有以下代码的 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
于 2013-02-03T22:18:02.187 回答