+ Reply to Thread
Results 1 to 5 of 5

Thread: if condition and then delete row

  1. #1
    Registered User
    Join Date
    03-28-2008
    Posts
    71

    if condition and then delete row

    Hello, I am hoping someone can help with my query.I have rows of data containing at least 5 columns.What I want to do is use an if statement on two columns such as If F4>4 and G4<8 than I want to retain that row.The rows that do not meet this criteria I want to delete those complete rows. Is this possible in an if statement.
    Gil

  2. #2
    Valued Forum Contributor JeanRage's Avatar
    Join Date
    03-02-2009
    Location
    Nice, France
    MS-Off Ver
    Excel 2003
    Posts
    705

    Re: if condition and then delete row

    Hi,

    No ...
    A formula will only allow you to spot the rows to be deleted ...
    To delete these rows, you will need a macro ...

    HTH

  3. #3
    Forum Contributor
    Join Date
    09-18-2007
    Posts
    116

    Re: if condition and then delete row

    You could do it in VBA with a command button or Macro Keys

  4. #4
    Forum Guru Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    5,587

    Re: if condition and then delete row

    This macro could be modified to suit

    
    Sub DeleteRowsWithConditionFalse()
        Dim LR As Long, i As Integer, c1 As Integer, c2 As Integer
        LR = Range("F" & Rows.Count).End(xlUp).Row
        c1 = Range("F1").Column
        c2 = Range("G1").Column
        For i = LR To 1 Step -1
            If Cells(i, c1).Value > 4 And Cells(i, c2).Value < 8 Then
                'Do nothing
            Else
                Rows(i).EntireRow.Delete xlShiftUp
            End If
        Next i
    End Sub
    Just insert in a standard vba module and adapt to suit - Try it in a copy of your workbook. You can't undo macro results.

  5. #5
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: if condition and then delete row

    Alternatively - use Auto Filter........

+ 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.2.0