突出显示两行

时间:2016-07-22 14:27:20

标签: excel vba excel-vba

我有输入信息的代码,然后将该信息与表格进行比较。我想突出显示正在创建的新行以及我们正在比较新行的那一行。这是我的代码

Sub findData()
    Dim workflow As String
    Dim finalrow As Integer
    Dim i As Integer

    With Sheets("Sheet1")
        workflow = .Range("C5").Value
        servergri = .Range("C9").Value
        gridf = .Range("C9").Value
        StartTime = .Range("c11").Value
    End With

    With Sheets("Sheet3")
        finalrow = .Range("C" & Rows.Count).End(xlUp).Row

        For i = 5 To finalrow
            If .Cells(i, 3) = workflow And (.Cells(i, 4) = servergri Or .Cells(i, 5) = gridf) Then

                .Rows(i).Insert
                'Add new information to the new row.
                'The new row number is still = i

                .Cells(i, 3) = workflow
                .Cells(i, 4) = servergri
                .Cells(i, 6) = StartTime


                'If you only want to add one row then your should exit the loop
                Exit For
            End If
        Next
    End With
    Call Worksheet_SelectionChange
End Sub

Sub Worksheet_SelectionChange()
    Dim Target As Range
    Application.ScreenUpdating = False
    ' Clear the color of all the cells
    Cells.Interior.ColorIndex = 0
    ' Highlight the active cell
    Target.Interior.ColorIndex = 8
    Application.ScreenUpdating = True
End Sub

1 个答案:

答案 0 :(得分:0)

只需添加

.Cells.Interior.ColorIndex = 0
.Cells(i, 3).Resize(2, 4).Interior.ColorIndex = 8

.Cells(i, 6) = StartTime