PC Review


Reply
Thread Tools Rate Thread

Conditional row deletion based on value in a row

 
 
=?Utf-8?B?Q3JhaWc=?=
Guest
Posts: n/a
 
      28th Dec 2005
I am trying to create a macro that will delete all rows in a worksheet that
have the value 0 in column B. The macro should only delete rows where the
value equals 0, and not rows where the value contains 0 (for example, 10).

Ideally I'd like to have this in a form that I could edit in the future, so
that if down the road I wanted to change the macro to delete all rows where
column F contained the value "Elephant", I could do so without starting from
scratch.
thank you,
Craig
 
Reply With Quote
 
 
 
 
Bob Umlas
Guest
Posts: n/a
 
      28th Dec 2005
Try this (untested)
Sub DeleteThem()
For i=Range("B65536").end(xlup).row to 1 step -1
if cells(i,2).value = 0 then rows(i).Delete
Next
End Sub

Sub DeleteElephantfromF()
For i=Range("F65536").end(xlup).row to 1 step -1
if cells(i,6).value = "Elephant" then rows(i).Delete
Next
End Sub

HTH
Bob Umlas
Excel MVP

"Craig" <(E-Mail Removed)> wrote in message
news:81A76517-49BB-47FF-8B68-(E-Mail Removed)...
> I am trying to create a macro that will delete all rows in a worksheet

that
> have the value 0 in column B. The macro should only delete rows where the
> value equals 0, and not rows where the value contains 0 (for example, 10).
>
> Ideally I'd like to have this in a form that I could edit in the future,

so
> that if down the road I wanted to change the macro to delete all rows

where
> column F contained the value "Elephant", I could do so without starting

from
> scratch.
> thank you,
> Craig



 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      28th Dec 2005
Craig,

Try code like the following:

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

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




"Craig" <(E-Mail Removed)> wrote in message
news:81A76517-49BB-47FF-8B68-(E-Mail Removed)...
>I am trying to create a macro that will delete all rows in a
>worksheet that
> have the value 0 in column B. The macro should only delete rows
> where the
> value equals 0, and not rows where the value contains 0 (for
> example, 10).
>
> Ideally I'd like to have this in a form that I could edit in
> the future, so
> that if down the road I wanted to change the macro to delete
> all rows where
> column F contained the value "Elephant", I could do so without
> starting from
> scratch.
> thank you,
> Craig



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      28th Dec 2005
One way is to apply Data|Filter|Autofilter to that column.

Then filtering to show the cells with the value you want to delete.

Then deleting those visible rows.

Record a macro when you do it and you'll have code you can modify.

Craig wrote:
>
> I am trying to create a macro that will delete all rows in a worksheet that
> have the value 0 in column B. The macro should only delete rows where the
> value equals 0, and not rows where the value contains 0 (for example, 10).
>
> Ideally I'd like to have this in a form that I could edit in the future, so
> that if down the road I wanted to change the macro to delete all rows where
> column F contained the value "Elephant", I could do so without starting from
> scratch.
> thank you,
> Craig


--

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
dual zero conditional row deletion Denise Microsoft Excel Programming 0 7th May 2008 08:49 PM
Conditional deletion of records TESA0_4 Microsoft Access VBA Modules 4 2nd Apr 2008 11:04 PM
Conditional Deletion Seeking help Microsoft Excel Programming 3 28th Jun 2006 06:19 AM
Conditional deletion of rows AussieExcelUser Microsoft Excel Programming 4 16th Jun 2006 02:43 AM
Conditional Row Deletion =?Utf-8?B?S2lyayBQLg==?= Microsoft Excel Programming 4 3rd Nov 2005 07:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:59 PM.