简体   繁体   English

突出显示相同的数据组合是否出现在另一行中

[英]highlight if the same combination of data appears in another row

enter image description here Hi does anyone know how to use excel vba to highlight if the same combination of data appears in another row, within the same group of items (an empty row is used to split them)?在此处输入图像描述嗨,有谁知道如何使用 excel vba 来突出显示相同的数据组合是否出现在同一组项目中的另一行中(空行用于拆分它们)? example例子

Try to this code it my help!试试这个代码,我的帮助!

Sub InsBl()
Dim rng, cel As Range
LR = Range("A" & Rows.Count).End(xlUp).Row
Set rng = Range("A2:A" & LR)
For Each cel In rng
If WorksheetFunction.CountIf(rng, cel.Value) > 1 Then
cel.Interior.ColorIndex = 6
Else
cel.Interior.ColorIndex = xlNone
End If
Next cel
End Sub

Dim rng, rng1, cel, cel1 As Range
LR = Range("A" & Rows.Count).End(xlUp).Row
Set rng = Range("B2:B" & LR)
Set rng1 = Range("C2:C" & LR)
For Each cel In rng
If WorksheetFunction.CountIf(rng, cel.Value) > 1 Then
For Each cel1 In rng1
If WorksheetFunction.CountIf(rng1, cel.Offset(0, 1).Value) > 1 Then
cel.Offset(0, 1).Interior.ColorIndex = 6
cel.Interior.ColorIndex = 6
End If
Next cel1
Else
cel.Interior.ColorIndex = xlNone
End If
Next cel

You can use conditional formatting with a "helper column"您可以将条件格式与“帮助列”一起使用

Formula for helper column:辅助列的公式:
column can be anyplace on the worksheet, and can be hidden列可以在工作表上的任何位置,并且可以隐藏

D2: =A2&B2&C2   *and fill down as far as needed*

Then select the three column/ranges to be formatted.然后 select 要格式化的三列/范围。 Conditional formatting using a formula:使用公式的条件格式:

=AND(COUNTIF($D$2:$D$15,$D2)>1,$D2<>"")

and set the format for your interior fill并为您的内部填充设置格式

Edit编辑
If the Items within each group are not all the same, as you are now showing in your revised example, then we merely add another helper column: Index with the formula:如果每个组中的项目不完全相同,正如您现在在修改后的示例中所示,那么我们只需添加另一个帮助列:索引和公式:

E2: =IF(A2="",ROW(),$E1)

And we change the concatenation formula in Column D to: D2: =TEXT($E2,"000")&B2&C2我们将 D 列中的连接公式更改为: D2: =TEXT($E2,"000")&B2&C2

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM