Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / June 2007

Tip: Looking for answers? Try searching our database.

deleting rows with a macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lucy - 01 Jun 2007 02:11 GMT
hi,
I am using Excel 2000 and would like to create a macro to delete rows that
do not contain specific text in column 1. so, if the cell does not contain
the words 'Centre' or 'Member' I would like to delete the row.  I am a bit of
a beginner to macros and have looked up the microsoft web-pages but couldn't
quite see what I was looking for. Any help would be appreciated.
Signature

lucy

JE McGimpsey - 01 Jun 2007 02:20 GMT
One way:

   Public Sub DeleteNonCentreMemberRows()
       Dim rCell As Range
       Dim rDelete As Range
       
       For Each rCell In Range("A1:A" & _
               Range("A" & Rows.Count).End(xlUp).Row)
           With rCell
               If Not (LCase(.Text) = "centre" Or _
                       LCase(.Text) = "member") Then
                   If rDelete Is Nothing Then
                       Set rDelete = .Cells
                   Else
                       Set rDelete = Union(rDelete, .Cells)
                   End If
               End If
           End With
       Next rCell
       If Not rDelete Is Nothing Then rDelete.EntireRow.Delete
   End Sub

> hi,
> I am using Excel 2000 and would like to create a macro to delete rows that
> do not contain specific text in column 1. so, if the cell does not contain
> the words 'Centre' or 'Member' I would like to delete the row.  I am a bit of
> a beginner to macros and have looked up the microsoft web-pages but couldn't
> quite see what I was looking for. Any help would be appreciated.
Don Guillett - 01 Jun 2007 13:43 GMT
Try this idea
Sub Deleteallrowsbut()
With Range("A3:A12")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="<>b", _
 Operator:=xlAnd, Criteria2:="<>other"
.EntireRow.Delete
End With
End Sub

Signature

Don Guillett
SalesAid Software
dguillett1@austin.rr.com

> hi,
> I am using Excel 2000 and would like to create a macro to delete rows that
[quoted text clipped - 4 lines]
> couldn't
> quite see what I was looking for. Any help would be appreciated.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.