电脑教程
位置:首页>> 电脑教程>> office教程>> Excel找出两列相同值的VBA宏代码

Excel找出两列相同值的VBA宏代码

  发布时间:2022-06-29 01:03:42 

标签:Excel找出两列相同值的VBA宏代码

以下的宏代码,其功能是,找到AB两列相同值,并存放到C列。

Sub MySubSearch()

Dim i As Integer

Dim c As Range

For i = 2 To Sheet1.[B65536].End(xlUp).Row

For Each c In Sheet1.Range("A2:A" & Sheet1.[A65536].End(xlUp).Row)

If Cells(i, 2).Value = c Then Cells(i, 2).Font.ColorIndex = 3

Next c

If Cells(i, 2).Font.ColorIndex = 3 Then _

Cells(Sheet1.[C65536].End(xlUp).Row + 1, 3).Value = Cells(i, 2).Value

Next i

MsgBox "所有重复编号已经找出,请查看结果!"

End Sub

0
投稿

猜你喜欢

手机版 电脑教程 asp之家 www.aspxhome.com