deleting rows based on text in a cell - not case sensative

bill151515

Board Regular
Joined
May 19, 2005
Messages
87
i have a column of data that has been presorted ascending.
i have a macro that goes down the column and deletes any duplicate rows


'code'

Set currentcell = Worksheets("IDSort").Range("A1")
Do While Not IsEmpty(currentcell)
Set nextcell = currentcell.Offset(1, 0)
If nextcell.Value = currentcell.Value Then
currentcell.EntireRow.Delete
End If
Set currentcell = nextcell
Loop



this is working fine except that i have some instances of ids that are duplicates (and need to be deleted) but the case is different ex.. 123xx56, 123XX56

is there a way to modify what I have and not have it be case sensative so that 1 of those would be deleted?? or a better way altogether to accompish this???
123
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
2 methods.

1 Put this at the top of the code.
Code:
Option Compare Text

2 Use this If statement.
Code:
If UCase(nextcell.Value) = UCase(currentcell.Value) Then

You could also look into using Advanced Filter to return only unique records.

To help with that we would need more information on the actual data.
 
Upvote 0
Something else to consider too...
If you will ever have more than two consecutive rows that meet the delete criteria then looping from the top down like that won't cut it.
Picture this. You have dupes in rows 4, 5 & 6.
Your loop has reached row 4, sees a dupe in row 5 so it deletes row 4. (as it should.)
Row 5 has just become row 4 and row 6 has just become row 5.
Excel has already checked row 4 against row 5 so it will move on to row 5 and check it against row 6. these do not match so it moves on.
You're left with matches in rows 4 & 5.

You can solve this one of a couple ways. Either (1) loop from the bottom up or (2) you can store the rows to be deleted for now and delete them all at once outside the loop.
 
Upvote 0
thanks

I used a combo of both your replies ....

using the UCAse() and looping from the bottom up

Thanks Alot!!!
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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