突出显示要复制的新数据

时间:2015-12-23 16:29:45

标签: excel vba with-statement

我有以下编码,如果没有匹配,它会复制" 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

1 个答案:

答案 0 :(得分:0)

您可以使用Range.Interior.Color属性更改单元格的背景。弄清楚要放入哪个数字以获得正确的颜色有点棘手。我通常会先找到我想要的颜色,然后选择相应的颜色,选择它并在即时窗口中键入?Selection.Interior.Color,这将打印下面的数字。

尝试使用laws.Cells(j, 5).Interior.Color = 8210719尺寸。