2015-02-06 72 views
0

即时通讯新的vba和我需要帮助重复颜色重复行而不是只有这个做的单元格,任何人都可以帮助我在这里。VBA:如何为重复行着色?

Sub FindDuplicate() 

Dim cel As Variant 
Dim myrng As Range 
Dim clr As Long 

Set myrng = Range("S2:S" & Range("S65536").End(xlUp).row) 
myrng.Interior.ColorIndex = xlNone 
clr = 3 

For Each cel In myrng 
    If Application.WorksheetFunction.CountIf(myrng, cel) > 1 Then 
     If WorksheetFunction.CountIf(Range("S2:S" & cel.row), cel) = 1 Then 
      cel.Interior.ColorIndex = 3 
     Else 
      cel.Interior.ColorIndex = myrng.Cells(WorksheetFunction.Match(cel.Value, myrng, False), 1).Interior.ColorIndex 
     End If 
    End If 
Next 

End Sub 

回答

1

在你的代码更改cel.Interior.ColorIndex = 3Rows(cel.Row).Interior.ColorIndex = 3,请记住我的回复作为答案,如果它的工作对你

0

我jeanno的回答,谢谢解决了这个问题。

我说:

Rows(cel.row).Interior.ColorIndex = 3 
     Else 
      Rows(cel.row).Interior.ColorIndex = myrng.Cells(WorksheetFunction.Match(cel.Value, myrng, False), 1).Interior.ColorIndex