萬盛學電腦網

 萬盛學電腦網 >> Excel教程 >> excel綜合 >> Excel找出兩列相同值的VBA宏代碼

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

copyright © 萬盛學電腦網 all rights reserved