满足条件时突出显示整行

时间:2014-01-27 10:58:00

标签: excel-vba excel-2010 vba excel

我正在尝试在满足条件时突出显示一个enitre行。我成功地能够突出显示包含单词的单元格,但无法突出显示该行。 Blow是我到目前为止的代码:

Sub Tester()
    Dim rng As Range

    Set rng = FindAll(Sheets("Current Tasks").Range("A:P"), "Completed")

    If Not rng Is Nothing Then
        rng.Rows(ActiveCell.Row).Interior.Color = 65535
        'rng.Interior.Color = 65535
        End If

End Sub



Public Function FindAll(rng As Range, val As String) As Range
    Dim rv As Range, f As Range
    Dim addr As String

    Set f = rng.Find(what:=val, after:=rng.Cells(rng.Cells.Count), _
        LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=False)
    If Not f Is Nothing Then addr = f.Address()

    Do Until f Is Nothing
        If rv Is Nothing Then
            Set rv = f
        Else
            Set rv = Application.Union(rv, f)
        End If
        Set f = rng.FindNext(after:=f)
        If f.Address() = addr Then Exit Do
    Loop

    Set FindAll = rv
End Function

1 个答案:

答案 0 :(得分:1)

您可以按如下方式稍微修改您的代码:

Sub Tester()
    Dim rng As Range

    Set rng = FindAll(Sheets("Current Tasks").Range("A:P"), "Completed")
    If Not rng Is Nothing Then
        rng.EntireRow.Interior.Color = 65535
    End If

End Sub