返回列表 上一主題 發帖

[發問] 請問是否可以用VBA 自動檢查重複名稱

回復 1# mark15jill
  1. Sub Ex()
  2.     Dim D As Object, R
  3.     Set D = CreateObject("Scripting.Dictionary")
  4.     For Each R In Range("A1").CurrentRegion.Columns(2).Cells
  5.         R.Interior.ColorIndex = xlNone
  6.         If Not D.EXISTS(R.Value) Then
  7.           Set D(R.Value) = R
  8.         Else
  9.           Set D(R.Value) = Union(D(R.Value), R)
  10.         End If
  11.     Next
  12.     For Each R In D.KEYS
  13.         If D(R).Cells.Count > 1 Then D(R).Interior.ColorIndex = 37
  14.     Next
  15. End Sub
複製代碼

TOP

回復 5# mark15jill
"大大 想請問一下 您這些程式是 以 A1 作為依據去搜索嗎?"
Range("A1").CurrentRegion.Columns(2).Cells
是以A1所延伸的範圍的第2欄Columns(2) 姓名欄作依據
可修改為Columns(?) 欄作依據
可察看CurrentRegion的說明

TOP

        靜思自在 : 信心、毅力、勇氣三者具備,則天下沒有做不成的事。
返回列表 上一主題