PC Review


Reply
Thread Tools Rate Thread

Delete worksheet row based on condition

 
 
=?Utf-8?B?bWllaw==?=
Guest
Posts: n/a
 
      23rd Aug 2007
Could someone help get me started on with the following:

I have text in column B that has a "P", "S", or "".
Number of rows varies, but ends with an empty row.

How do I step through each row and test if column B
has a value <> "P", delete that row?

Thanks for any help
 
Reply With Quote
 
 
 
 
Bob Umlas
Guest
Posts: n/a
 
      23rd Aug 2007
Sub DeleteNotP()
'do it backwards so deleting rows doesn't mess this up!
for i=range("B65536").end(xlup).Row to 1 step -1
if cells(i,2).value <> "P" then rows(i).Delete
Next
End Sub
Bob Umlas
Excel MVP


"miek" <(E-Mail Removed)> wrote in message
news:5935370C-2402-4B6D-B385-(E-Mail Removed)...
> Could someone help get me started on with the following:
>
> I have text in column B that has a "P", "S", or "".
> Number of rows varies, but ends with an empty row.
>
> How do I step through each row and test if column B
> has a value <> "P", delete that row?
>
> Thanks for any help



 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      23rd Aug 2007
The delay function should be put at the top of the module. It allows time
for the delete action to complete before going to the next cell. Otherwise,
some of the rows might not delete.

Public Function HalfSecDly()
s = Timer + 0.1
Do While Timer < s
DoEvents
Loop
End Function

Sub delRw()
lr = Cells(Rows.Count, 2).End(xlUP).Row
For each c in Range("B2:B" & lr)
If c <> "P" Then
c.EntireRow.Delete
HalfSecDly
End If
Next
End Sub

"miek" wrote:

> Could someone help get me started on with the following:
>
> I have text in column B that has a "P", "S", or "".
> Number of rows varies, but ends with an empty row.
>
> How do I step through each row and test if column B
> has a value <> "P", delete that row?
>
> Thanks for any help

 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      23rd Aug 2007
You're right Bob. I'm slipping into senility here.

"Bob Umlas" wrote:

> Sub DeleteNotP()
> 'do it backwards so deleting rows doesn't mess this up!
> for i=range("B65536").end(xlup).Row to 1 step -1
> if cells(i,2).value <> "P" then rows(i).Delete
> Next
> End Sub
> Bob Umlas
> Excel MVP
>
>
> "miek" <(E-Mail Removed)> wrote in message
> news:5935370C-2402-4B6D-B385-(E-Mail Removed)...
> > Could someone help get me started on with the following:
> >
> > I have text in column B that has a "P", "S", or "".
> > Number of rows varies, but ends with an empty row.
> >
> > How do I step through each row and test if column B
> > has a value <> "P", delete that row?
> >
> > Thanks for any help

>
>
>

 
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
CheckBox values based on Worksheet condition Steve Morgan Microsoft Excel Programming 2 21st Jun 2010 06:46 PM
how to delete a row based on a condition ya Microsoft Excel Programming 2 17th Dec 2008 03:59 PM
Delete Worksheet Condition =?Utf-8?B?Vmlja2k=?= Microsoft Excel Programming 1 7th Nov 2006 04:13 PM
copy data from 1 worksheet to another based on a condition vinisunodh@gmail.com Microsoft Excel Worksheet Functions 9 4th Sep 2006 02:45 PM
how to hide section of worksheet based on a condition (e.g. tick . =?Utf-8?B?a2l0ZXB1cHBldA==?= Microsoft Excel Misc 2 4th Mar 2005 06:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:15 PM.