PC Review


Reply
Thread Tools Rate Thread

Delete Rows based on cell values.

 
 
Little Penny
Guest
Posts: n/a
 
      25th Sep 2007
I am trying to expand on my simple macro to:

Look in column B and if it finds the value "No Employee" to select
that row and delete it. I also would like look in column C for values
that are 500 or less and delete that row.

My data could be as little as 75 rows to several hundred rows. And
these values could appear several times in there respective columns.
I'm not sure how to get the code to delete multiple instances.


Sub RemoveEmployee()
If Range("B5").Value = "No Employee" Then

Rows("5:5").Select
Selection.Delete Shift:=xlUp
End If
End Sub

 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      25th Sep 2007
One way is one at a time such as

for i=cells(rows.count,"b").end(xlup).row to 2 step -1
if cells(i,"b")="No Employee" or cells(i,"c")<500 then rows(i).delete
next

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Little Penny" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am trying to expand on my simple macro to:
>
> Look in column B and if it finds the value "No Employee" to select
> that row and delete it. I also would like look in column C for values
> that are 500 or less and delete that row.
>
> My data could be as little as 75 rows to several hundred rows. And
> these values could appear several times in there respective columns.
> I'm not sure how to get the code to delete multiple instances.
>
>
> Sub RemoveEmployee()
> If Range("B5").Value = "No Employee" Then
>
> Rows("5:5").Select
> Selection.Delete Shift:=xlUp
> End If
> End Sub
>


 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      25th Sep 2007
This will start at the last row containing data in column B and run
backwards to row #2. At anytime during the cycle, if column B of the
row = "No Employee" or column C of the row is less than or equal to
500, the row will be deleted.
Sub RemoveEmployee()
Dim r As Long
For r = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
If Cells(r, 2).Text = "No Employee" Or _
Cells(r, 3).Value <= 500 Then Rows(r).EntireRow.Delete
Next r
End Sub
Little Penny wrote:
> I am trying to expand on my simple macro to:
>
> Look in column B and if it finds the value "No Employee" to select
> that row and delete it. I also would like look in column C for values
> that are 500 or less and delete that row.
>
> My data could be as little as 75 rows to several hundred rows. And
> these values could appear several times in there respective columns.
> I'm not sure how to get the code to delete multiple instances.
>
>
> Sub RemoveEmployee()
> If Range("B5").Value = "No Employee" Then
>
> Rows("5:5").Select
> Selection.Delete Shift:=xlUp
> End If
> End Sub


 
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
Deleting rows based on values in a a cell in the row Martin Microsoft Excel New Users 1 25th Jan 2009 11:46 AM
Delete Rows based on cell value BrianWest83@gmail.com Microsoft Excel Programming 7 18th Jan 2008 04:29 AM
Delete rows based on a cell value in the row =?Utf-8?B?RGF2ZQ==?= Microsoft Excel Discussion 7 14th Mar 2006 06:44 PM
Can I automate copy of rows based on cell values =?Utf-8?B?cnZlYWNoNjQ=?= Microsoft Excel Programming 0 20th Dec 2005 06:21 PM
Delete rows based on Cell name gmunro Microsoft Excel Programming 1 25th Nov 2005 01:09 PM


Features
 

Advertising
 

Newsgroups
 


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