![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Mar 2002
Location: Philippines
Posts: 55
|
I am using Excel 2000.
I have a spreadsheet with 55000 e-mail addresses in column A. In order to remove duplicates I used the following macro code: Sub delete_duplicates() rowx = 1 Do Until Cells(rowx + 1, 1).Value = "" If UCase(Cells(rowx, 1).Value) = UCase(Cells(rowx + 1, 1).Value) Then Cells(rowx + 1, 1).EntireRow.Delete Else rowx = rowx + 1 End If Loop End Sub Some of the addresses have an additional "REMOVED" added to the end of it, indicating the e-mail address is no longer valid. How can I modify the above code to delete those rows as well. Hans |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Try the following code:
If Right(Cells(rowx, 1).Value, 7) = "REMOVED" Then Cells(rowx + 1, 1).EntireRow.Delete
__________________
Kind regards, Al Chara |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Mar 2002
Location: Near the Land of Oz
Posts: 1,550
|
Hans, thanks for the macro. I have been looking for exactly that process for a long time.
Rich
__________________
- old, slow, and confused ... but at least I'm inconsistent - (retired Excel 2003 user, 3.28.2008)
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Mar 2002
Location: Philippines
Posts: 55
|
Al Chara,
tried it out, had to add a ")" after the word REMOVED, but it gives me the message: "Runtime Error 13 - type mismatch" What now, shoot myself? Hans |
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
The following code is what I am using and it works:
rowx = 1 If UCase(Right(Cells(rowx, 1).Value, 7)) = "REMOVED" Then Cells(rowx, 1).EntireRow.Delete End If
__________________
Kind regards, Al Chara |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Mar 2002
Location: Philippines
Posts: 55
|
Used your code exactly and it deleted every row except the first one wich contained REMOVED in it.
Dont worry, I had a backup. Gonna shoot myself anyway. Where is my mistake: Sub delete_removed() rowx = 1 Do Until Cells(rowx + 1, 1).Value = "" If Right(Cells(rowx, 1).Value, 7 = "REMOVED") Then Cells(rowx + 1, 1).EntireRow.Delete Else rowx = rowx + 1 End If Loop End Sub Hans |
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Mar 2002
Location: Philippines
Posts: 55
|
Sub delete_removed()
rowx = 1 Sorry posted the old code. Here is the "Killer Code" Do Until Cells(rowx + 1, 1).Value = "" If UCase(Right(Cells(rowx, 1).Value, 7)) = "REMOVED" Then Cells(rowx + 1, 1).EntireRow.Delete Else rowx = rowx + 1 End If Loop End Sub |
|
|
|
|
|
#8 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
The following code worked for me:
rowx = 1 Do Until Cells(rowx + 1, 1).Value = "" If UCase(Right(Cells(rowx, 1).Value, 7)) = "REMOVED" Then Cells(rowx, 1).EntireRow.Delete Else rowx = rowx + 1 End If Loop I think you had "rowx+1" when you needed just "rowx"
__________________
Kind regards, Al Chara |
|
|
|
|
|
#9 |
|
Board Regular
Join Date: Mar 2002
Location: Philippines
Posts: 55
|
IT WORKS!
Shitty little + Thanks Hans |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|