Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 3 of 3

Thread: Delete Row When Cell Not Equal To Another

  1. #1
    Join Date
    8th July 2004
    Location
    CA., USA
    Posts
    171

    Delete Row When Cell Not Equal To Another

    The code below is an attempt to delete all rows where the cell in column A is not equal to the value of B1. B1 is text if that somehow makes a difference.
    VB:
    Dim n As Long, lastrow As Long 
    lastrow = Range("A65536").End(xlUp).Row 
    For n = lastrow To 1 Step -1 
        If Cells(n, 1) <> Range("B1") Then Cells(n, 1).EntireRow.Delete 
    Next n 
    
    
    Do I need to specify that B1 will always be the cell to reference (ie $B$1).
    Thanks for the help.

    Edit: Just had an epiphany, I also need it to stop after Row 3. I have some headers and such that I don't want removed. Any help there would be appreciated.
    Last edited by Foxxy1; February 28th, 2007 at 04:51.
    Ed
    *ficus*
    Thanks to all for making this website work!

  2. #2
    Join Date
    26th January 2003
    Location
    Derbyshire,UK
    Posts
    18,442

    Re: Delete Row When Cell Not Equal To Anothert

    This works for me
    VB:
    Dim n As Long, lastrow As Long 
    lastrow = Range("A65536").End(xlUp).Row 
    For n = lastrow To 3 Step -1 
        If Cells(n, 1).Value <> Cells(1, 2).Value Then Cells(n, 1).EntireRow.Delete 
    Next n 
    
    
    Hope that Helps

    Roy

    For free Excel tools & articles visit my web site

    If I have helped you and you feel like putting your hand in your pocket please make a donation to Children in Need

    RoyUK's Web Site

    royUK's Database Form

    Where to paste code from the Forum

    About me.

  3. #3
    Join Date
    8th July 2004
    Location
    CA., USA
    Posts
    171

    Re: Delete Row When Cell Not Equal To Another

    Thanks Roy.
    Ed
    *ficus*
    Thanks to all for making this website work!

Thread Information

Users Browsing this Thread

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

Possible Answers

  1. Delete Subtotal Groups That Equal Zero
    By pastlife in forum EXCEL HELP
    Replies: 12
    Last Post: March 30th, 2008, 13:14
  2. Delete Row When Cells Dont Equal
    By Boriqua73 in forum EXCEL HELP
    Replies: 1
    Last Post: September 8th, 2007, 00:54
  3. Delete Rows Where Cell Doesn't Equal Adjacent Cell
    By drmeatrx in forum EXCEL HELP
    Replies: 3
    Last Post: August 16th, 2007, 15:18
  4. Delete row if not equal to value
    By bigjaker in forum EXCEL HELP
    Replies: 2
    Last Post: March 21st, 2006, 01:21
  5. If cells equal, concatenate and delete row
    By Reg1988 in forum EXCEL HELP
    Replies: 3
    Last Post: February 14th, 2006, 12:33

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
  •  
porno