PC Review


Reply
Thread Tools Rate Thread

delete rows if data is either

 
 
aileen
Guest
Posts: n/a
 
      8th Oct 2008
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!
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      8th Oct 2008
spelling?
spaces?

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"aileen" <(E-Mail Removed)> wrote in message
news:A581EBBF-AAEB-44A4-A5B5-(E-Mail Removed)...
> 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!


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      8th Oct 2008
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
 
Reply With Quote
 
aileen
Guest
Posts: n/a
 
      8th Oct 2008
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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete rows with data =?Utf-8?B?QW15THlubjkxNTY=?= Microsoft Excel Programming 3 10th Jul 2007 09:32 PM
How do I delete blank rows (rows alternate data, blank, data, etc =?Utf-8?B?bmNvY2hyYXg=?= Microsoft Excel Misc 2 27th Jun 2007 04:40 AM
Delete rows with no data =?Utf-8?B?TWluZGll?= Microsoft Excel Setup 1 30th Nov 2005 09:24 PM
Delete rows if certain data in rows scain2004 Microsoft Excel Programming 1 11th Mar 2004 10:39 PM
Delete certain rows of data... RMJ Microsoft Excel Programming 3 26th Jan 2004 08:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:12 PM.