nair.harish
New Member
- Joined
- Mar 2, 2010
- Messages
- 40
Hi
The below macro works perfectly, except that it does not highlight duplicate lines on a particular sheet. If there are 3 similar lines it highlights only one and moves forward. heres the link to the workbook (http://www57.zippyshare.com/view.jsp?locale=en&key=97096454), i have marked it in red the lines that did not highlight. the consolidated sheet is where the macro refers which lines to highlight.
Sub replaceColours()
Dim cl As Range
Dim CI As Long
Dim i As Integer
Dim strText As String
For Each cl In ActiveSheet.UsedRange.Columns(1).Cells
CI = cl.Interior.Color
If CI <> 16777215 Then
strText = cl.Value
For i = 1 To Worksheets.Count
' find next instance of strText
Dim rngNext As Range: Set rngNext = Worksheets(i).Cells.Find(What:=strText, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
' if found, colour it
If Not rngNext Is Nothing Then rngNext.Interior.Color = CI
Next i
End If
Next cl
End Sub
The below macro works perfectly, except that it does not highlight duplicate lines on a particular sheet. If there are 3 similar lines it highlights only one and moves forward. heres the link to the workbook (http://www57.zippyshare.com/view.jsp?locale=en&key=97096454), i have marked it in red the lines that did not highlight. the consolidated sheet is where the macro refers which lines to highlight.
Sub replaceColours()
Dim cl As Range
Dim CI As Long
Dim i As Integer
Dim strText As String
For Each cl In ActiveSheet.UsedRange.Columns(1).Cells
CI = cl.Interior.Color
If CI <> 16777215 Then
strText = cl.Value
For i = 1 To Worksheets.Count
' find next instance of strText
Dim rngNext As Range: Set rngNext = Worksheets(i).Cells.Find(What:=strText, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
' if found, colour it
If Not rngNext Is Nothing Then rngNext.Interior.Color = CI
Next i
End If
Next cl
End Sub