Excel找出两列相同值的VBA宏代码
2026年09月12日 23:27 发布来源:Excel学习网
以下的宏代码,其功能是,找到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
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
原创文章如转载请注明:转载自Excel学习网 [ https://www.excelxxw.com/]
需要保留本文链接地址:https://www.excelxxw.com/jiqiao/2687.html
需要保留本文链接地址:https://www.excelxxw.com/jiqiao/2687.html
上一篇:返回excel 最后一行的位置和内容的公式
下一篇:返回列表
相关教程:
经典Excel学习视频及教程推荐:
Excel优秀工具推荐:
小工具推荐:
