ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   delete rows if data is either (https://www.excelbanter.com/excel-programming/418274-delete-rows-if-data-either.html)

aileen

delete rows if data is either
 
I'm trying to delete rows based on whether the data in column G is "adj" or
"redi avg". I am using the following code, but it is only deleting the rows
with "adj" in the cell:

Dim lr As Long, i As Long
lr = ActiveSheet.Cells(Rows.Count, 7).End(xlUp).Row
For i = lr To 1 Step -1
With ActiveSheet
If .Cells(i, 7) = "adj" Or .Cells(i, 7) = "redi avg" Then
.Cells(i, 1).EntireRow.Delete
End If
End With
Next

Please let me know how to get the rows with "redi avg" to delete also.
Thanks!

Don Guillett

delete rows if data is either
 
spelling?
spaces?

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"aileen" wrote in message
...
I'm trying to delete rows based on whether the data in column G is "adj"
or
"redi avg". I am using the following code, but it is only deleting the
rows
with "adj" in the cell:

Dim lr As Long, i As Long
lr = ActiveSheet.Cells(Rows.Count, 7).End(xlUp).Row
For i = lr To 1 Step -1
With ActiveSheet
If .Cells(i, 7) = "adj" Or .Cells(i, 7) = "redi avg" Then
.Cells(i, 1).EntireRow.Delete
End If
End With
Next

Please let me know how to get the rows with "redi avg" to delete also.
Thanks!



Dave Peterson

delete rows if data is either
 
I bet the cells that contain "redi avg" contain more than those
characters--maybe extra spaces???

If that's true, maybe you could eliminate those spaces with:

If trim(.Cells(i, 7).value) = "adj" _
Or trim(.Cells(i, 7).value) = "redi avg" Then

Or you maybe your string is in upper case???

If lcase(trim(.Cells(i, 7).value)) = lcase("adj") _
Or lcase(trim(.Cells(i, 7).value)) = lcase("redi avg") Then



aileen wrote:

I'm trying to delete rows based on whether the data in column G is "adj" or
"redi avg". I am using the following code, but it is only deleting the rows
with "adj" in the cell:

Dim lr As Long, i As Long
lr = ActiveSheet.Cells(Rows.Count, 7).End(xlUp).Row
For i = lr To 1 Step -1
With ActiveSheet
If .Cells(i, 7) = "adj" Or .Cells(i, 7) = "redi avg" Then
.Cells(i, 1).EntireRow.Delete
End If
End With
Next

Please let me know how to get the rows with "redi avg" to delete also.
Thanks!


--

Dave Peterson

aileen

delete rows if data is either
 
That worked. Thanks so much.

"Dave Peterson" wrote:

I bet the cells that contain "redi avg" contain more than those
characters--maybe extra spaces???

If that's true, maybe you could eliminate those spaces with:

If trim(.Cells(i, 7).value) = "adj" _
Or trim(.Cells(i, 7).value) = "redi avg" Then

Or you maybe your string is in upper case???

If lcase(trim(.Cells(i, 7).value)) = lcase("adj") _
Or lcase(trim(.Cells(i, 7).value)) = lcase("redi avg") Then



aileen wrote:

I'm trying to delete rows based on whether the data in column G is "adj" or
"redi avg". I am using the following code, but it is only deleting the rows
with "adj" in the cell:

Dim lr As Long, i As Long
lr = ActiveSheet.Cells(Rows.Count, 7).End(xlUp).Row
For i = lr To 1 Step -1
With ActiveSheet
If .Cells(i, 7) = "adj" Or .Cells(i, 7) = "redi avg" Then
.Cells(i, 1).EntireRow.Delete
End If
End With
Next

Please let me know how to get the rows with "redi avg" to delete also.
Thanks!


--

Dave Peterson



All times are GMT +1. The time now is 08:03 AM.

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