請測試看看,謝謝
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Arr, xD, C%, T$, m&, i&
If Target.Column = 3 Then C = 3
If Target.Column = 4 Then C = 4
Set xD = CreateObject("Scripting.Dictionary")
With Sheets("客戶基本資料")
Arr = .Range(.Cells(1, C), .Cells(Rows.Count, C).End(3))
.Range(.Cells(1, C), .Cells(Rows.Count, C).End(3)).Font.ColorIndex = 0
.Range(.Cells(1, C), .Cells(Rows.Count, C).End(3)).Interior.ColorIndex = 0
For i = 1 To UBound(Arr)
T = Arr(i, 1)
If xD.Exists(T) Then
m = xD(T)
Cells(m, C).Font.ColorIndex = 3
Cells(m, C).Interior.ColorIndex = 36
Cells(i, C).Font.ColorIndex = 3
Cells(i, C).Interior.ColorIndex = 36
End If
xD(T) = i
Next
End With
End Sub作者: cypd 時間: 2022-7-24 11:33
C 或 D 欄出現相同數據時...刪除下列數據之後儲存格會有填滿之 ...
cypd 發表於 2022-7-24 20:23
請測試看看,謝謝
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Arr, xD, C%, T$, m&, i&
If Target.Column = 3 Then C = 3
If Target.Column = 4 Then C = 4
If C = 0 Then Exit Sub
Set xD = CreateObject("Scripting.Dictionary")
With Sheets("客戶基本資料")
.Unprotect Password:="1234" '解保護,密碼自行修改
Arr = .Range(.Cells(1, C), .Cells(Rows.Count, C).End(3))
.Range(.Cells(1, C), .Cells(Rows.Count, C)).Font.ColorIndex = 0
.Range(.Cells(1, C), .Cells(Rows.Count, C)).Interior.ColorIndex = 0
For i = 1 To UBound(Arr)
T = Arr(i, 1)
If xD.Exists(T) Then
m = xD(T)
.Cells(m, C).Font.ColorIndex = 3
.Cells(m, C).Interior.ColorIndex = 36
.Cells(i, C).Font.ColorIndex = 3
.Cells(i, C).Interior.ColorIndex = 36
End If
xD(T) = i
Next
.Unprotect Password:="1234" '保護,密碼自行修改
End With
End Sub作者: cypd 時間: 2022-7-25 10:21