Announcement

Collapse
No announcement yet.

Unconfigured Ad Widget

Collapse

Delete Row When Cell Not Equal To Another

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.
    Code:
        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, 04:51.
    Ed
    *ficus*
    Thanks to all for making this website work!

  • #2
    Re: Delete Row When Cell Not Equal To Anothert

    This works for me
    Code:
    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

    New users should read the Forum Rules before posting

    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.

    Comment


    • #3
      Re: Delete Row When Cell Not Equal To Another

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

      Comment

      Trending

      Collapse

      There are no results that meet this criteria.

      Working...
      X