Results 1 to 5 of 5

Thread: delete rows based on value in a column cell that is > or equal to 0
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jan 2019
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default delete rows based on value in a column cell that is > or equal to 0

    I need to create a macro to delete rows if the value of a cell in column J is > or = to zero. The worksheet will vary in length, but will always use columns C through J. I know this is easy, but I can't get it right. Any help is greatly appreciated!

  2. #2
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    South Western NSW
    Posts
    17,885
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: delete rows based on value in a column cell that is > or equal to 0

    MAybe this

    Code:
    Sub MM1()
    Dim lr As Long, r As Long
    lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
    For r = lr To 2 Step -1
      If Cells(r, "J") >= 0 Then Rows(r).Delete
    Next r
    End Sub
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

  3. #3
    New Member
    Join Date
    Jan 2019
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: delete rows based on value in a column cell that is > or equal to 0

    Thank you Michael!

    I also need to have it omit the header and start with row 6. What I did below did not work.


    Sub DeleteRow()


    Dim FirstRow As Long
    FirstRow = 6
    Dim lr As Long, r As Long
    lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
    For r = lr To 2 Step -1


    If Cells(r, "J") >= 0 Then Rows(r).Delete


    Next r


    End Sub

  4. #4
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    South Western NSW
    Posts
    17,885
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: delete rows based on value in a column cell that is > or equal to 0

    Change this line

    Code:
    For r = lr To 2 Step -1
    To

    Code:
    For r = lr To 6 Step -1
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

  5. #5
    New Member
    Join Date
    Jan 2019
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: delete rows based on value in a column cell that is > or equal to 0

    Thank you Michael - that worked perfectly! I have been messing with this all day - I appreciate your quick solution!

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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