+ Reply to Thread
Results 1 to 4 of 4

Delete rows based on specific value in cell

Hybrid View

ExcelBG Delete rows based on specific... 05-03-2017, 04:53 AM
bakerman2 Re: Delete rows based on... 05-03-2017, 04:59 AM
ExcelBG Re: Delete rows based on... 05-03-2017, 05:02 AM
bakerman2 Re: Delete rows based on... 05-03-2017, 05:37 AM
  1. #1
    Registered User
    Join Date
    02-17-2013
    Location
    Bulgaria
    MS-Off Ver
    Excel 2007
    Posts
    45

    Delete rows based on specific value in cell

    Hi all

    I`m trying to write macro for helping me to delete rows based on specific cell value.

    My macro is:

    Sub deleterows()
    
    Dim rng As Range
    
    Set rng = Sheets("Sheet1").Range("A1:A10")
     For i = rng.Count To 1 Step -1
      If Cells(i, 1).Value = 0 Then
      Rows(i, 1).EntireRow.Delete
      End If
     Next
    
    End Sub
    Every time when i try to run this macro it gives me error 1004. Could someone help me?
    Last edited by ExcelBG; 05-03-2017 at 05:02 AM.

  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,637

    Re: Delete rows based on specific value in cell

    Sub deleterows()
    
    Dim rng As Range, i As Long
    
    Set rng = Sheets("Sheet1").Range("A1:A10")
     For i = rng.Rows.Count To 1 Step -1
      If Cells(i, 1).Value = 0 Then
      Rows(i).EntireRow.Delete
      End If
     Next
    
    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
    Registered User
    Join Date
    02-17-2013
    Location
    Bulgaria
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: Delete rows based on specific value in cell

    A lot of tnx bakerman 2!

    It works perfect.

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

    Re: Delete rows based on specific value in cell

    You're welcome.

+ 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. Macro to delete rows based on contents of specific column
    By WarZak in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-31-2015, 04:58 PM
  2. [SOLVED] Delete Table Rows Based on Specific Text
    By gedwards913 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-10-2015, 12:47 PM
  3. delete specific rows based on values in that row
    By bstinson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-05-2013, 03:46 PM
  4. [SOLVED] Macro to Delete Rows based on Specific Conditions
    By stockgoblin42 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-28-2013, 05:29 PM
  5. How can I delete rows based on specific criteria using a macro?
    By akouleze in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-24-2011, 02:49 AM
  6. Delete rows based on specific criteria
    By Archana in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2007, 05:00 AM
  7. [SOLVED] I want to delete certain rows based on specific criteria
    By Alaphas in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2005, 07:06 PM

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