如果满足三个条件,如何突出显示一行?

如果满足以下条件: 对于第10行和第100行之间的任何给定行,包括: A列中的单元格不为空 B列中的单元格不为空 列O中的单元格为空 我想强调一个特定的单元格(让我们说A1)。 例: 我填充A10和E10,同时将O10留空,然后单元格A1突出显示。如果我然后填充单元格O10,则单元格A1中的突出显示消失。 我可以进入下一行。任何时候任何行都应该生成这些操作。 谢谢!     
已邀请:
这将根据您指定的条件执行突出显示。当你运行它时,它将在你需要在列O中输入内容的第一行停止。如果你希望它继续运行直到第101行并突出显示所有行,然后删除然后在2结束之间的退出操作命令声明。
Sub Highlight()

    Dim TheRow As Integer

    TheRow = 9

    Application.ScreenUpdating = False 'This hides the visual process and speeds up
                                        'the execution

    Do

        TheRow = TheRow + 1

        If TheRow = 101 Then Exit Do

        Cells(TheRow, 1).Select
        Selection.Interior.Pattern = 0

        Cells(TheRow, 2).Select
        Selection.Interior.Pattern = 0

        If Not Cells(TheRow, 1).Value = "" And Not Cells(TheRow, 2).Value = "" And Cells(TheRow, 15).Value = "" Then

            If Cells(TheRow, 1).Value = "" Then
                Cells(TheRow, 1).Select
                Selection.Interior.Color = 656
            End If

             If Cells(TheRow, 2).Value = "" Then
                Cells(TheRow, 2).Select
                Selection.Interior.Color = 656
            End If

            Exit Do  'this is the line to remove if you want to highlight all cells

        End If

    Loop

    Application.ScreenUpdating = True

End Sub
然后,创建一个事件处理程序,在第15列中的单元格发生更改时触发。将以下代码放在实际工作表的模块中(在VBA项目资源管理器中,双击要使用此功能的工作表;不要将其放在不同的模块中!)
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 15 Then
        If Target.Row > 9 And Target.Row < 101 Then Call Highlight
End Sub
如果此解决方案有效,请告诉我并记住点击“接受解决方案”并投票支持! 快乐的编码。     
您不需要VBA:只需使用以下公式在单元格A10上使用条件格式:
=AND(NOT(ISBLANK($A10)),NOT(ISBLANK($B10)),ISBLANK($O10))
    
好的 - 我误解了你想要的东西。这是一个VBA UDF来进行检查。 在单元格A1中输入
=Checker($A$10:$B$100,$O$10:$O$100)
,然后在单元格A1上使用条件格式,当它变为True时触发。
Public Function Checker(theRangeAB As Range, theRangeO As Variant) As Boolean
    Dim varAB As Variant
    Dim varO As Variant
    Dim j As Long

    varAB = theRangeAB.Value2
    varO = theRangeO.Value2

    Checker = False
    For j = 1 To UBound(varAB)
        If Not IsEmpty(varAB(j, 1)) And Not IsEmpty(varAB(j, 2)) Then
            If IsEmpty(varO(j, 1)) Then
                Checker = True
                Exit For
            End If
        End If
    Next j

End Function
    

要回复问题请先登录注册