突出显示正在复制的新数据

Highlight new data being copied over

我有以下代码,如果不匹配,它会复制 "new" 信息(第 1 至 9 列)。有人可以建议添加代码以突出显示添加的每一行新数据,以便我可以轻松辨别现有数据和新行吗?谢谢!

Sub CompareSheets()

Dim laws As Worksheet
Set laws = Sheets("LookAhead")
Dim galreqws As Worksheet
Set galreqws = Sheets("galreq")

Dim RowsMaster As Integer, Rows2 As Integer
RowsMaster = laws.Cells(1048576, 1).End(xlUp).Row
Rows2 = galreqws.Cells(1048576, 1).End(xlUp).Row
' Get the number of used rows for each sheet


With Worksheets("galreq")
    For i = 2 To Rows2
    ' Loop through Sheet 2
        For j = 2 To RowsMaster
        ' Loop through the Master sheet
            If .Cells(i, 4) = laws.Cells(j, 4) And .Cells(i, 6) = laws.Cells(j, 6) And .Cells(i, 8) = laws.Cells(j, 8) Then
            ' If a match is found:
                laws.Cells(j, 5) = .Cells(i, 5)
                ' Copy in contact info
                Exit For
                ' No point in continuing the search for that company
            ElseIf j = RowsMaster Then
            ' If we got to the end of the Master sheet
            ' and haven't found a company match
                RowsMaster = RowsMaster + 1
                ' Increment the number of rows
                For k = 1 To 9 ' Change 3 to however many fields Sheet2 has
                    laws.Cells(RowsMaster, k) = .Cells(i, k)
                    ' Copy the data from Sheet2 in on the bottom row of Master
                Next
            End If
        Next j
    Next i
End With
End Sub

您可以使用 Range.Interior.Color 属性 更改单元格的背景。要弄清楚在其中输入什么数字以获得正确的颜色有点棘手。我通常会先找到我想要的颜色,然后确定相应的数字,方法是选择它并在立即 window 中输入 ?Selection.Interior.Color,这将立即在下面打印数字。

试穿 laws.Cells(j, 5).Interior.Color = 8210719 尺码。