我是 Excel VBA 的初学者。我只是想知道如何使此代码排除 A 列中的重复项。我不确定要编写哪些代码来排除重复项。
我只想突出显示不重复的行。
我希望你能帮助我。谢谢你。
Sub Test2()
Dim count, i As Long
count = ActiveSheet.Cells(Rows.count, "A").End(xlUp).Row
i = 2
Do While i <= count
If Cells(i, 3).Value Like "Expired" Then
Range(Cells(i, 1), Cells(i, 5)).Interior.Color = RGB(230, 98, 76)
ElseIf Cells(i, 3).Value Like "New" Then
Range(Cells(i, 1), Cells(i, 5)).Interior.Color = RGB(118, 234, 62)
End If
i = i + 1
Loop
End Sub
Cells(i, 3).Value Like "New"
与Cells(i, 3).Value = "New"
相同。
如果您想使用不区分大小写的比较,请尝试
If StrComp(Cells(i, 3).Value, "New", vbTextCompare)=0 Then
Option Explicit
Sub Test2()
Dim count as Long, i As Long
count = ActiveSheet.Cells(Rows.count, "A").End(xlUp).Row
i = 2
Do While i <= count
If Application.CountIf(Columns(1), Cells(i, 1)) = 1 Then
If Cells(i, 3).Value Like "Expired" Then
Range(Cells(i, 1), Cells(i, 5)).Interior.Color = RGB(230, 98, 76)
ElseIf Cells(i, 3).Value Like "New" Then
Range(Cells(i, 1), Cells(i, 5)).Interior.Color = RGB(118, 234, 62)
End If
End If
i = i + 1
Loop
End Sub
条件格式也是一个选项。
CF 公式
=AND($C2="New",COUNTIF($A:$A,$A2)=1)
=AND($C2="Expired",COUNTIF($A:$A,$A2)=1)