ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If field in column is blank, delete if.... (https://www.excelbanter.com/excel-programming/306075-if-field-column-blank-delete-if.html)

CPower[_30_]

If field in column is blank, delete if....
 
Hi all,

I have a macro statement that, if a field in a certain column is blan
it will look to another column in the same row, and if that fiel
contains a certain name it will delete the entire row. I want
statement that will NOT delete the row if it contains a certain name
i.e. if any field in col E is blank look to col D and delete the entir
row if it does not contain Mark, Brian and Karl.

Can anyone please help me on this??

Thanks in advance,

Cathal

--
Message posted from http://www.ExcelForum.com


Dave Peterson[_3_]

If field in column is blank, delete if....
 
I _think_ that this does what you want:

Option Explicit
Sub testme02()

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "D").End(xlUp).Row

For iRow = LastRow To FirstRow Step -1
If IsEmpty(.Cells(iRow, "e")) Then
Select Case LCase(.Cells(iRow, "D").Value)
Case Is = "mark", "brian", "karl"
'do nothing
Case Else
.Rows(iRow).Delete
End Select
End If
Next iRow
End With

End Sub

I did use column D to find the last row.

"CPower <" wrote:

Hi all,

I have a macro statement that, if a field in a certain column is blank
it will look to another column in the same row, and if that field
contains a certain name it will delete the entire row. I want a
statement that will NOT delete the row if it contains a certain name.
i.e. if any field in col E is blank look to col D and delete the entire
row if it does not contain Mark, Brian and Karl.

Can anyone please help me on this??

Thanks in advance,

Cathal.

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson



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

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