Highlight equal row text

Manolocs

Active Member
Joined
Mar 28, 2008
Messages
340
Hello, How to Highlight two consecutive equal text cells in a table ? I have to find, identify and manually delete multiple rows of an extensive table with 5 columns, the search for consecutive identical rows is needed by the column "A" only, the other columns maybe not equal. I tried already with conditional formatting but while I am deleting the entire row, the conditional missed a lot of identical cells.
Any idea how to make it easier?
Thanks in advance.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hello, How to Highlight two consecutive equal text cells in a table ? I have to find, identify and manually delete multiple rows of an extensive table with 5 columns, the search for consecutive identical rows is needed by the column "A" only, the other columns maybe not equal. I tried already with conditional formatting but while I am deleting the entire row, the conditional missed a lot of identical cells.
Any idea how to make it easier?
Thanks in advance.
Hi Manolocs,

You could use the following macro to highlight the duplicate rows:

Code:
Sub RemoveDupes()
' Defines variables
Dim x As Long, LastRow As Long, cRange As Range


' Defines LastRow as the last row of data based on column A
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row


' Sets the check range as A1 to the last row of A
Set cRange = Range("A1:A" & LastRow)


' For each cell in the check range, working from the bottom upwards
For x = cRange.Cells.Count To 1 Step -1
    With cRange.Cells(x)
        ' If the count of the cell value is more than 1 then...
        If Application.WorksheetFunction.CountIf(cRange, .Value) > 1 Then
            ' Highlight the row with yellow fill
            .EntireRow.Interior.ColorIndex = 6
        End If
    End With
' Check next cell in check range
Next x


End Sub

Or better yet to save manually removing the duplicates this slightly modified version of the code above will directly remove one of the duplicates instead of just highlight it:

Code:
Sub RemoveDupes()
' Defines variables
Dim x As Long, LastRow As Long, cRange As Range


' Defines LastRow as the last row of data based on column A
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row


' Sets the check range as A1 to the last row of A
Set cRange = Range("A1:A" & LastRow)


' For each cell in the check range, working from the bottom upwards
For x = cRange.Cells.Count To 1 Step -1
    With cRange.Cells(x)
        ' If the count of the cell value is more than 1 then...
        If Application.WorksheetFunction.CountIf(cRange, .Value) > 1 Then
            ' Delete that row
            .EntireRow.Delete
        End If
    End With
' Check next cell in check range
Next x


End Sub
 
Upvote 0
Hi FishBoy, I got an error in this line:

"If Application.WorksheetFunction.CountIf(cRange, .Value) > 1 Then"

Run-time error '1004'
Method 'Countif' of object 'WorksheetFunction failed

Sorry I am not familiar with macros :(
 
Upvote 0
Hi FishBoy, I got an error in this line:

"If Application.WorksheetFunction.CountIf(cRange, .Value) > 1 Then"

Run-time error '1004'
Method 'Countif' of object 'WorksheetFunction failed

Sorry I am not familiar with macros :(
Hmm, are we dealing with a single sheet here? Or at least one at a time? How many rows are in your tables? Are the tables completely consecutive or is there a gap between the two?
 
Upvote 0
there is only one sheet, and the rows are consecutives and sorted A-Z no gaps, there are more than thousands lines :(
 
Last edited:
Upvote 0
there is only one sheet, and the rows are consecutives and sorted A-Z no gaps, there are more than thousands lines :(
Hmm, download my test document HERE and let me know if you get the error. If you don't then there is something about your set up that is different.
 
Upvote 0
Yours is working but is not deleting all of them.... at the end of the run still have 27 rows....
I would prefer your first example. then I can chose the ones I need to delete because I will delete according with the other columns.... the "A" collumn is only to show the rows that have the first column the same.
 
Upvote 0
Yours is working but is not deleting all of them.... at the end of the run still have 27 rows....
I would prefer your first example. then I can chose the ones I need to delete because I will delete according with the other columns.... the "A" collumn is only to show the rows that have the first column the same.
There should have only been 26 rows left (A through Z) as the code was purposefully only deleting 1 of the duplicates if more than 1 were counted. Even if there had been 6 of the same thing, you would have ended up with only 1 of them at the end.

To tweak my code to highlight instead see the updated version below:

Rich (BB code):
Sub RemoveDupes()
' Defines variables
Dim x As Long, LastRow As Long, DupeCount As Long, cRange As Range


' Defines LastRow as the last row of data based on column A
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row




' Sets the check range as A1 to the last row of A
Set cRange = Range("A1:A" & LastRow)


' Sets DupeCount to zero
DupeCount = 0


' Update status bar
Application.StatusBar = "Highlighting Duplicates...Please Wait"


' Disables screen updating to reduce flicker
Application.ScreenUpdating = False


' For each cell in the check range, working from the bottom upwards
For x = cRange.Cells.Count To 1 Step -1
    With cRange.Cells(x)
        ' If the count of the cell value is more than 1 then...
        If Application.WorksheetFunction.CountIf(cRange, .Value) > 1 Then
            ' Highlight that row with yellow fill
            .EntireRow.Interior.ColorIndex = 6
            DupeCount = DupeCount + 1
        End If
    End With
' Check next cell in check range
Next x


' Re-enables screen updating
Application.ScreenUpdating = True


' Update status bar
Application.StatusBar = "Task Complete"


' Optional message box confirming task is complete
MsgBox DupeCount & " Duplicates Highlighted", vbOKOnly, "Task Complete!"


End Sub
 
Upvote 0
now the error is back, I updated your code to your spreadsheet and the error is the same... :(
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,676
Members
449,463
Latest member
Jojomen56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top