VBA - 从两个范围复制所有相应的值

时间:2017-10-06 08:42:03

标签: vba copy compare

我想比较两个范围,然后从C列复制那些与列O具有共同值的单元格。现在,它只复制最后一个共同的单元格,而不是全部。但如果我将细胞染成红色,则所有细胞共同变成红色。我做错了什么?

Sub CompareRangesOrigineel()
Dim WorkRng1 As Range, WorkRng2 As Range, Rng1 As Range, Rng2 As Range
Set WorkRng1 = Range("C5:C31")
Set WorkRng2 = Range("O3:O30")
For Each Rng1 In WorkRng1
    rng1Value = Rng1.Value
    For Each Rng2 In WorkRng2
        If rng1Value = Rng2.Value And Not IsEmpty(Rng1) Then
            Rng1.Copy
            Rng1.Interior.Color = VBA.RGB(500, 0, 0)
        End If
    Next
Next
End Sub

0 个答案:

没有答案