ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete Row meeting a Criteria (https://www.excelbanter.com/excel-programming/292661-delete-row-meeting-criteria.html)

SRS Man

Delete Row meeting a Criteria
 
Is there a way to delete a row that meets a certain criteria using VBA.

For example, my spreadsheet has 100 rows and I want to delete every row that
has the word "DUP" in it. They will be spreadout over the 100 rows.

Please let me know.

Thanks




Chip Pearson

Delete Row meeting a Criteria
 
Try something like the following:

Dim RowNdx As Long
Dim LastRow As Long
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "A").Value = "DUP" Then
Rows(RowNdx).Delete
End If
Next RowNdx

This will delete all the rows that have "DUP" in column A.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"SRS Man" wrote in message
...
Is there a way to delete a row that meets a certain criteria

using VBA.

For example, my spreadsheet has 100 rows and I want to delete

every row that
has the word "DUP" in it. They will be spreadout over the 100

rows.

Please let me know.

Thanks






SRS Man

Delete Row meeting a Criteria
 
Thanks Chip


"Chip Pearson" wrote in message
...
Try something like the following:

Dim RowNdx As Long
Dim LastRow As Long
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "A").Value = "DUP" Then
Rows(RowNdx).Delete
End If
Next RowNdx

This will delete all the rows that have "DUP" in column A.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"SRS Man" wrote in message
...
Is there a way to delete a row that meets a certain criteria

using VBA.

For example, my spreadsheet has 100 rows and I want to delete

every row that
has the word "DUP" in it. They will be spreadout over the 100

rows.

Please let me know.

Thanks








Robert McCurdy

Delete Row meeting a Criteria
 
Hi Man.

Sounds like "DUP" is the result of a formula looking for duplicates.
If so why not change this to 0 (zero) and sort by that column, and then delete the rows with 0?


Regards Robert

"SRS Man" wrote in message ...
Is there a way to delete a row that meets a certain criteria using VBA.

For example, my spreadsheet has 100 rows and I want to delete every row that
has the word "DUP" in it. They will be spreadout over the 100 rows.

Please let me know.

Thanks





---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.593 / Virus Database: 376 - Release Date: 20/02/2004




All times are GMT +1. The time now is 05:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com