+ Reply to Thread
Results 1 to 4 of 4

Delete entire row based on criteria

Hybrid View

D_N_L Delete entire row based on... 11-08-2011, 05:51 AM
nilem Re: Delete entire row based... 11-08-2011, 06:09 AM
Steffen Thomsen Re: Delete entire row based... 11-08-2011, 06:33 AM
D_N_L Re: Delete entire row based... 11-08-2011, 09:13 AM
  1. #1
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Delete entire row based on criteria

    Morning all,

    I have attached an example worksheet. Sheets 1 and 2 show you how my data is now.

    To explain, based on the name column ('B') I would like the code to delete the ENTIRE ROW when a person only features on either sheet 1 or 2 (but not both). For example, in the attached the person called 'Dave' would be deleted from Sheet 1 because he only features on Sheet 1 and not Sheet 2.

    So if a person is present on both sheets then they are left alone. The spelling of each name will always be correct but the list of names may be in different orders (as they are in sheet 1 and 2 in the example).

    Thanks
    Attached Files Attached Files
    Last edited by D_N_L; 11-08-2011 at 09:13 AM.

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete entire row based on criteria

    Try it. Now rows are highlighted. If everything is correct, delete this line
    If Not rDel Is Nothing Then rDel.EntireRow.Interior.ColorIndex = 36
    and uncomment this line
    '        If Not rDel Is Nothing Then rDel.EntireRow.Delete
    Attached Files Attached Files
    Last edited by nilem; 11-08-2011 at 10:21 AM. Reason: Fixed a bag in file

  3. #3
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Delete entire row based on criteria

    Hi,

    Here's a bit shorter code

    
    Sub Steffen()
    
    For Each cell In Sheets(1).Range("B3:B" & Sheets(1).UsedRange.Rows.Count)
        If Sheets(2).Cells.Find(cell, , xlValues, xlPart) Is Nothing Then
            cell.EntireRow.Delete shift:=xlUp
        End If
    Next cell
    
    End Sub
    Steffen Thomsen

  4. #4
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Delete entire row based on criteria

    Guys, that is brilliant!!! Thanks so much!!

    I went with Steffen's in the end. Code was shorter. Thanks!!!

+ 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