Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Delete worksheet row based on condition

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 301
Default Delete worksheet row based on condition

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" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Delete worksheet row based on condition

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Delete worksheet row based on condition

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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Rows based on condition Vic Excel Discussion (Misc queries) 2 August 18th 09 08:54 PM
Delete row 1 based on condition in cell on row 2 McDuck Excel Worksheet Functions 0 July 30th 08 07:53 PM
How to delete a data row based on a condition wmc New Users to Excel 4 April 18th 07 02:40 PM
Is there a way to delete a cell value based on a condition? Peanut Excel Discussion (Misc queries) 2 October 2nd 06 09:55 PM
Delete Columns based on a condition Joel Mills Excel Programming 3 August 6th 04 07:21 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"