如何比较范围在 excel 上的两列?
How can I compare two columns with a range on excel?
如何比较 excel 上的两列?考虑到我想比较几行,例如:在 A1-A10 与 B1-B-10 值之间比较
使用行差异。
Sub SelectDiffRws()
Dim Rws As Long, Rng As Range, rng2 As Range, c As Range
Rws = Cells(Rows.Count, "A").End(xlUp).Row
Set Rng = Range(Cells(2, 1), Cells(Rws, 2))
Set rng2 = Rng.RowDifferences(Range("A2"))
Columns("A:B").Interior.Color = xlNone
For Each c In rng2.Cells
Range(Cells(c.Row, 1), Cells(c.Row, 2)).Interior.ColorIndex = 3
Next c
End Sub
例子见这里
http://www.xlorate.com/vba-examples.html#Column%20Differences
剪辑请看这里
https://youtu.be/Fcq4rgigu3w
可共享 link 至 sample workbook
如何比较 excel 上的两列?考虑到我想比较几行,例如:在 A1-A10 与 B1-B-10 值之间比较
使用行差异。
Sub SelectDiffRws()
Dim Rws As Long, Rng As Range, rng2 As Range, c As Range
Rws = Cells(Rows.Count, "A").End(xlUp).Row
Set Rng = Range(Cells(2, 1), Cells(Rws, 2))
Set rng2 = Rng.RowDifferences(Range("A2"))
Columns("A:B").Interior.Color = xlNone
For Each c In rng2.Cells
Range(Cells(c.Row, 1), Cells(c.Row, 2)).Interior.ColorIndex = 3
Next c
End Sub
例子见这里 http://www.xlorate.com/vba-examples.html#Column%20Differences
剪辑请看这里 https://youtu.be/Fcq4rgigu3w
可共享 link 至 sample workbook