将颜色添加到代码粘贴

时间:2017-10-24 14:08:45

标签: excel vba excel-vba

我有以下内容将新的数据行移动到目标工作表(wsdest)。我添加了(Interior.color = RGB(10,90,175)部分以确保添加了特定颜色的新添加的线条,因此它们很突出。它工作正常,但我似乎无法让它工作随着颜色的变化。

With wsSource


 RowCount = .Cells(.Cells.Rows.Count, "A").End(xlUp).Row

    For i = 1 To RowCount
        If .Cells(i, "BH").Value = 5 Then

            If WorksheetFunction.CountIf(wsDest.Range("A:A"), .Cells(i, "A").Value) = 0 Then
                .Cells(i, "A").Copy wsDest.Cells(.Rows.Count, "A").End(xlUp).Offset(1)
                wsDest.Cells(.Rows.Count, "A").Interior.Color = RGB(10, 90, 175)
            End If
        End If
    Next i
End With

1 个答案:

答案 0 :(得分:1)

尝试下面的代码,我做了一些修改:

With wsSource
    RowCount = .Cells(.Rows.Count, "A").End(xlUp).Row ' <-- modifed this line

    For i = 1 To RowCount
        If .Cells(i, "BH").Value = 5 Then

            If WorksheetFunction.CountIf(wsDest.Range("A:A"), .Cells(i, "A").Value) = 0 Then
                .Cells(i, "A").Copy wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1) ' <-- modifed this line
                wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Interior.Color = RGB(10, 90, 175) ' <-- modifed this line
            End If
        End If
    Next i
End With