Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro for fast deletion of rows that conatin certain data.

I need a macro that deletes all rows in a worksheet in which a certain text
string is found in a cell in that row? e.g. If a cell in column "B" contains
a text string "6:00 AM", then delete the entire row.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Macro for fast deletion of rows that conatin certain data.

Try the below

Sub DeleteRows()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, 2).End(xlUp).Row To 1 Step -1
If Range("B" & lngRow).Text = "6:00 AM" Then Rows(lngRow).Delete
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"PhilBennett" wrote:

I need a macro that deletes all rows in a worksheet in which a certain text
string is found in a cell in that row? e.g. If a cell in column "B" contains
a text string "6:00 AM", then delete the entire row.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,480
Default Macro for fast deletion of rows that conatin certain data.

Hi Phil

I would loop through the file starting at the last row and build a
collection of the rows with the text 6:00 AM in them, then delete that
collection at the finish of the routine.

Sub DeleteRows6AM()
Dim lr As Long, i As Long
Dim delrng As Range, ws As Worksheet
Set ws = ActiveSheet
lr = ws.Cells(Rows.Count, 2).End(xlUp).Row
For i = lr To 1 Step -1
If Cells(i, 2).Text = "6:00 AM" Then
If delrng Is Nothing Then
Set delrng = ws.Rows(i)
Else
Set delrng = Application.Union(delrng, ws.Rows(i))
End If
End If
Next
delrng.Delete
End Sub

--
Regards
Roger Govier

"PhilBennett" wrote in message
...
I need a macro that deletes all rows in a worksheet in which a certain
text
string is found in a cell in that row? e.g. If a cell in column "B"
contains
a text string "6:00 AM", then delete the entire row.

__________ Information from ESET Smart Security, version of virus
signature database 4527 (20091020) __________

The message was checked by ESET Smart Security.

http://www.eset.com




__________ Information from ESET Smart Security, version of virus signature database 4527 (20091020) __________

The message was checked by ESET Smart Security.

http://www.eset.com



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
Fast Way to Delete Rows from Big Spreadsheet (Using VBA) LarryP Excel Programming 5 May 21st 08 02:44 PM
Automatic Deletion of Rows ai18ma New Users to Excel 6 April 5th 06 08:25 AM
On deletion of rows Stephen Howe Excel Discussion (Misc queries) 2 October 7th 05 06:02 PM
Need a fast way to delete rows glenlee Excel Discussion (Misc queries) 1 September 23rd 05 03:33 AM
Deletion of rows where a value is satisfied Larry Wallis[_2_] Excel Programming 2 February 22nd 05 01:36 PM


All times are GMT +1. The time now is 01:57 AM.

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

About Us

"It's about Microsoft Excel"