+ Reply to Thread
Results 1 to 4 of 4

Deleting a row if it contains the right criteria

Hybrid View

  1. #1
    Registered User
    Join Date
    11-19-2010
    Location
    Saint Louis
    MS-Off Ver
    Excel 2003
    Posts
    1

    Deleting a row if it contains the right criteria

    Hello,

    I have a project that I'm working on and stuck at trying to figure this part out. It is in a larger database of information and I need a macro that will analyze one column of data and delete the entire row if it's value is under 30 sec.

    Help!

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Re: Deleting a row if it contains the right criteria

    you dont say which column to look at so you can adjust this yourself!
    Sub Del_If_under_30()
    'Code supplied by Simon Lloyd
    '19/11/2010
    'Microsoft Office Help
    'Excel Conference Poll
    Dim rRow As Double, i As Double
    
    rRow = Range("A" & Rows.Count).End(xlUp).Row
    For i = rRow To 1 Step -1
        If Range("A" & rRow).Value < 30 Then
            Rows(rRow).EntireRow.Delete
        End If
    Next i
    End Sub
    Not all forums are the same - seek and you shall find

  3. #3
    Registered User
    Join Date
    11-13-2010
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Deleting a row if it contains the right criteria

    With this one you can do the action for any selection of yours...



    Option Explicit
    
    
    Sub delete()
    Dim dvalue As Double
    Dim cell As Range
    
    
    For Each cell In Selection
    
        If ActiveCell.Value < 30 Then
            ActiveCell.EntireRow.delete
            ActiveCell.Offset(-1, 0).Activate
        End If
            
            ActiveCell.Offset(1, 0).Activate
            Next cell
            
    End Sub

  4. #4
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Re: Deleting a row if it contains the right criteria

    Quote Originally Posted by lakshithaw View Post
    With this one you can do the action for any selection of yours...



    Option Explicit
     
     
    Sub delete()
    Dim dvalue As Double
    Dim cell As Range
     
     
    For Each cell In Selection
     
        If ActiveCell.Value < 30 Then
            ActiveCell.EntireRow.delete
            ActiveCell.Offset(-1, 0).Activate
        End If
     
            ActiveCell.Offset(1, 0).Activate
            Next cell
     
    End Sub
    You will have lots of problems if you choose to do it this way, firstly selecting or activating all the time will slow excel down and is not necessary, secondly you should always delete from the bottom up

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1