繁体   English   中英

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

[英]Coloring multiple cells of an excel sheet based on the value of a particular cell

我有一张Excel工作表...我想根据以下条件为单元格上色:

  1. 如果单元格E为非空,则单元格A,单元格B,单元格C,单元格D,单元格F,单元格G,单元格H和单元格I不能为空。 如果发现任何一个单元为空,则将各个单元涂成红色!

  2. 如果所有单元格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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM