+ Reply to Thread
Results 1 to 3 of 3

Delete Rows Based on Cell Value

Hybrid View

  1. #1
    Registered User
    Join Date
    02-08-2017
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    77

    Delete Rows Based on Cell Value

    Hi All,

    I want to thank you thank you in advance for any help that you can provide. I am hoping this is a relatively straightforward question, but because I am a novice at VBA this is still a little over my head. I have attached an example spreadsheet so you can follow along with what I am asking.

    I have data that I pull that comes out in all different size ranges. It could be anywhere from 6 to 15 columns. And anywhere from 3000 - 10,000 rows. What I am looking for is VBA code that will delete rows based on whether a cell has a value of 0 or a negative value. The good news is that these values are always in the same column.

    For example, in this spreadsheet in Column D, I have both positive, negative and zero values. What I would need is for any row that has a 0 or negative value in Column D to be deleted. I should also mention that this data is already set as a Table as it is in this example spreadsheet and I am unable to change that. I'm hoping this is good news since the Table already has filters on it.

    I appreciate any help!

    Thank you
    Attached Files Attached Files

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,569

    Re: Delete Rows Based on Cell Value

    How about this one.

    Sub tst()
        With Sheet1.ListObjects("Table1")
            For i = .ListRows.Count To 1 Step -1
                If .DataBodyRange(i, 4) <= 0 Then .ListRows(i).Delete
            Next
        End With
    End Sub
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,072

    Re: Delete Rows Based on Cell Value

    Another Option...
    Sub DeleteRows()
    With Cells(1).CurrentRegion
        .AutoFilter 4, "<=0"
        .Offset(1).EntireRow.Delete
        .AutoFilter
    End With
    End Sub
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Delete rows based on cell value
    By Pojzon in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-05-2018, 03:20 PM
  2. [SOLVED] VBA to delete certain rows based on the value of a cell
    By The_Snook in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-13-2018, 05:28 AM
  3. [SOLVED] BEST way to delete rows based on cell value
    By EchoPassenger in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-22-2017, 01:51 PM
  4. Delete rows based on the value of a cell
    By Emma_B in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-04-2013, 05:35 PM
  5. Delete certain rows based on value in another cell
    By angelk in forum Excel General
    Replies: 1
    Last Post: 07-30-2012, 02:38 PM
  6. Delete Rows based on cell value and then Insert rows alternatively with a formula
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-11-2008, 04:27 PM
  7. [SOLVED] Delete rows based on Cell name
    By gmunro in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-25-2005, 09:15 AM

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