Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Macros / April 2008

Tip: Looking for answers? Try searching our database.

Deleting Rows Based on Criteria

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bgoode - 24 Apr 2008 16:16 GMT
I'm a newbie to VBA and am trying to construct a simple macro to delete all
rows containing different characters.

For instance, delete all

- blank rows
- rows beginning "pgm"
- rows beginning "load"
- rows containing "total"

and some others.

I attempted to do this by copying a tutorial macro as below

Sub DeleteCells2()

   Dim rng As Range
   Dim i As Integer, counter As Integer

   'Set the range to evaluate to rng.
   Set rng = Range("A1:A10")

   'initialize i to 1
   i = 1

   'Loop for a count of 1 to the number of rows
   'in the range that you want to evaluate.
   For counter = 1 To rng.Rows.Count

       'If cell i in the range contains an "x",
       'delete the row.
       'Else increment i
       If rng.Cells(i) = "x" Then
           rng.Cells(i).EntireRow.Delete
       Else
           i = i + 1
       End If

   Next

End Sub

and then substituting my values for the "x".  This took care of the blank
cells fine but when I insert "pgm*" or "=pgm*" instead of " " then nothing is
deleted.  I haven't added additional if statments for the other criteria
because I want to make sure I can run this simple part and understand it.

Any suggestions would be appreaciated.
bgoode - 24 Apr 2008 16:33 GMT
Please ignore...now that I found this group and have read the others I have
some additional reading to do.

> I'm a newbie to VBA and am trying to construct a simple macro to delete all
> rows containing different characters.
[quoted text clipped - 44 lines]
>
> Any suggestions would be appreaciated.
 
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.