我需要幫助弄清楚如何突出顯示重復項但不突出顯示或與 A 列中具有“IMD Exempel”的值進行比較。
這是我現在的代碼,但它突出顯示了每個重復項。
Dim Rng As Range
Dim cel As Range
Set Rng = Range(Range("C8"), Range("C" & Rows.Count).End(xlUp))
For Each cel In Rng
If WorksheetFunction.CountIf(Rng, cel.Value) > 1 Then
cel.Interior.Color = RGB(255, 255, 153)
Else
cel.Interior.ColorIndex = xlNone
End If
Next cel
在此示例螢屏截圖中,我不希望突出顯示任何內容。

提前致謝!
uj5u.com熱心網友回復:
嘗試使用 COUNTIFS():
Dim Rng As Range, Rng_A As Range
Dim cel As Range
Set Rng = Range(Range("C8"), Range("C" & Rows.Count).End(xlUp))
Set Rng_A = Range(Range("A8"), Range("A" & Rows.Count).End(xlUp))
For Each cel In Rng
If WorksheetFunction.CountIfs(Rng, cel.Value, Rng_A, "<>IMD Exempel") > 1 Then
cel.Interior.Color = RGB(255, 255, 153)
Else
cel.Interior.ColorIndex = xlNone
End If
Next cel
更新代碼:
Dim Rng As Range, Rng_A As Range
Dim cel As Range, LastRow As Long, i As Long
LastRow = Cells(Rows.Count, "C").End(xlUp).Row
Set Rng = Range(Range("C8"), Range("C" & Rows.Count).End(xlUp))
Set Rng_A = Range(Range("A8"), Range("A" & Rows.Count).End(xlUp))
For i = 8 To LastRow
If (WorksheetFunction.CountIfs(Rng, Cells(i, 3).Value, Rng_A, "<>IMD Exempel") > 1) And (Cells(i, 1).Value <> "IMD Exempel") Then
Cells(i, 3).Interior.Color = RGB(255, 255, 153)
Else
Cells(i, 3).Interior.ColorIndex = xlNone
End If
Next i
- 添加了額外的條件以不突出顯示 A 的值是否為
IMD Exempel - 由于我們無法過濾 A 的值,因此我們正在使用
Cells()overrange并FOR loop稍微調整一下 - 我們正在使用
Lastrow手動和喂入FOR loop
在上面的代碼中,我添加了另一個條件來檢查即, <> IMD Exempel
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/401384.html
