Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.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
根据特定单元格的值为excel工作表的多个单元格着色_Excel_Vba - Fatal编程技术网

根据特定单元格的值为excel工作表的多个单元格着色

根据特定单元格的值为excel工作表的多个单元格着色,excel,vba,Excel,Vba,我有一张excel表格…我想根据以下条件为单元格着色: 如果单元E不为空,则单元A、单元B、单元C、单元D、单元F、单元G、单元H和单元I不能为空。如果发现任何一个单元格为空,则将相应的单元格涂成红色 如果所有单元格(单元格A、单元格B、单元格C、单元格D、单元格F、单元格G、单元格H和单元格I)都包含一个值,且单元格E为空,则以红色突出显示单元格E 注意:希望在模块部分实现此功能…因此建议相应的解决方案 您喜欢这项工作吗 Dim Row Row = 3 If Not IsEmpty(Cell

我有一张excel表格…我想根据以下条件为单元格着色:

  • 如果单元E不为空,则单元A、单元B、单元C、单元D、单元F、单元G、单元H和单元I不能为空。如果发现任何一个单元格为空,则将相应的单元格涂成红色

  • 如果所有单元格(单元格A、单元格B、单元格C、单元格D、单元格F、单元格G、单元格H和单元格I)都包含一个值,且单元格E为空,则以红色突出显示单元格E


  • 注意:希望在模块部分实现此功能…因此建议相应的解决方案

    您喜欢这项工作吗

    Dim Row
    Row = 3
    
    If Not IsEmpty(Cells(Row, 5)) Then
        ' if Cell E is not empty, then highlight empty cols A-I
        For chkcol = 1 To 9
            If chkcol <> 5 Then ' ignore column E
                If IsEmpty(Cells(Row, chkcol)) Then
                    Cells(Row, chkcol).Interior.ColorIndex = 3
                End If
            End If
        Next
    Else
        blnvalid = True
        ' check for cell E being empty and all others not
        For chkcol = 1 To 9
            If chkcol <> 5 Then
                If IsEmpty(Cells(Row, chkcol)) Then
                    blnvalid = False
                    Exit For
                End If
            End If
        Next
        If blnvalid Then
            Cells(Row, 5).Interior.ColorIndex = 3
        End If
    End If
    
    Dim行
    行=3
    如果不是IsEmpty(单元格(第5行)),则
    '如果单元格E不为空,则突出显示空列A-I
    对于chkcol=1到9
    如果是chkcol 5,则忽略列E
    如果为空(单元格(行,chkcol)),则
    单元格(行,chkcol).Interior.ColorIndex=3
    如果结束
    如果结束
    下一个
    其他的
    blnvalid=True
    '检查单元格E是否为空,其他所有单元格是否为空
    对于chkcol=1到9
    如果chkcol 5,则
    如果为空(单元格(行,chkcol)),则
    blnvalid=False
    退出
    如果结束
    如果结束
    下一个
    如果BLN有效,那么
    单元格(第5行)。Interior.ColorIndex=3
    如果结束
    如果结束
    
    您喜欢这项工作吗

    Dim Row
    Row = 3
    
    If Not IsEmpty(Cells(Row, 5)) Then
        ' if Cell E is not empty, then highlight empty cols A-I
        For chkcol = 1 To 9
            If chkcol <> 5 Then ' ignore column E
                If IsEmpty(Cells(Row, chkcol)) Then
                    Cells(Row, chkcol).Interior.ColorIndex = 3
                End If
            End If
        Next
    Else
        blnvalid = True
        ' check for cell E being empty and all others not
        For chkcol = 1 To 9
            If chkcol <> 5 Then
                If IsEmpty(Cells(Row, chkcol)) Then
                    blnvalid = False
                    Exit For
                End If
            End If
        Next
        If blnvalid Then
            Cells(Row, 5).Interior.ColorIndex = 3
        End If
    End If
    
    Dim行
    行=3
    如果不是IsEmpty(单元格(第5行)),则
    '如果单元格E不为空,则突出显示空列A-I
    对于chkcol=1到9
    如果是chkcol 5,则忽略列E
    如果为空(单元格(行,chkcol)),则
    单元格(行,chkcol).Interior.ColorIndex=3
    如果结束
    如果结束
    下一个
    其他的
    blnvalid=True
    '检查单元格E是否为空,其他所有单元格是否为空
    对于chkcol=1到9
    如果chkcol 5,则
    如果为空(单元格(行,chkcol)),则
    blnvalid=False
    退出
    如果结束
    如果结束
    下一个
    如果BLN有效,那么
    单元格(第5行)。Interior.ColorIndex=3
    如果结束
    如果结束
    
    为什么不把它作为条件格式呢?我试着为每一列写一个单独的检查,然后在一个单独的函数中顺序调用它们……这似乎不是一个好主意!!为什么不把它作为条件格式呢?我试着为每一列写一个单独的检查,然后在一个单独的函数中顺序调用它们…这似乎不是一个好主意!!