Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 阅读Excel for Mac中有多少单元格具有特定颜色_Macos_Excel - Fatal编程技术网

Macos 阅读Excel for Mac中有多少单元格具有特定颜色

Macos 阅读Excel for Mac中有多少单元格具有特定颜色,macos,excel,Macos,Excel,我正在使用Office 2011 for Mac,在Excel应用程序中,是否可以读取一行中有多少单元格是红色的?下面是一个AppleScript,它返回具有红色填充的单元格的列数和行数。或者您正在寻找一种除AppleScript之外的语言 tell application "Microsoft Excel" tell active sheet set lastColumn to used range's last column's first column index

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

下面是一个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

我打赌像
这样的单行脚本告诉应用程序“Microsoft Excel”,告诉活动工作表返回内部对象颜色为{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

我正在寻找任何可以在MacOSX上工作的东西;我不关心语言,除非它能工作,或者我需要安装任何额外的语言/东西,因为你使用的是Mac,没有额外的安装。只需将代码粘贴到AppleScript编辑器中即可。是的,Office 2011 for Mac具有VBA,只需转到工具->宏->Visual Basic编辑器。然后在VBE左侧的项目窗口中,右键单击项目树中的任意位置,然后插入->模块。粘贴代码,您可以从“工具”->“宏”->“宏”菜单运行代码,或指定快捷键