+ Reply to Thread
Results 1 to 12 of 12

Macro - delete entire row if cell contains specific value

  1. #1
    Registered User
    Join Date
    03-25-2015
    Location
    Zagreb, Croatia
    MS-Off Ver
    Office 365
    Posts
    94

    Macro - delete entire row if cell contains specific value

    hi folks,

    i have a macro which deletes the entire row when in column A is a specific value, in my case 555555.
    can anybody please tell me how i can add specific values in the macro.

    know the macro is deleting rows when in column A is value 555555, no i want
    to delete also rows with 666666, and 888888. is there a possibility to "refresh" the macro
    when i have to add new sped. values?

    here is the macro:

    Sub myDeleteRows()

    Dim MyCol As String
    Dim i As Integer
    For i = 1 To Range("A" & "65536").End(xlUp).Row Step 1
    If Application.WorksheetFunction.CountIf(Range("A" & i & ":AZ" & i), "555555") > 0 Then
    Range("A" & i).EntireRow.Delete
    End If
    Next i

    End Sub



    thx in advance!!

    mandura

  2. #2
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Macro - delete entire row if cell contains specific value

    you can change the if like so:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-25-2015
    Location
    Zagreb, Croatia
    MS-Off Ver
    Office 365
    Posts
    94

    Re: Macro - delete entire row if cell contains specific value

    unfortunately not working?
    probably i am pasting your if formala the wrong way?

    can you give me the whole macro please?

    thank you very much!!

    mandura.

  4. #4
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Macro - delete entire row if cell contains specific value

    Could you post a sample workbook?

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro - delete entire row if cell contains specific value

    Maybe:

    Please Login or Register  to view this content.
    Or

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    03-25-2015
    Location
    Zagreb, Croatia
    MS-Off Ver
    Office 365
    Posts
    94

    Re: Macro - delete entire row if cell contains specific value

    John H. Davis,

    both macros are working perfectly!

    i tried in the first macro to add 444444 as spec. value, and it works to.
    i just have to copy the row "Range("A1:A" & Range("A" & Rows.Count).End(3).row).AutoFilter 1, 888888"
    and paste it under and change 888888 to 444444, so i can refresh the macro and add new values.

    thank you very much you helped me a lot!

    cheers!

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro - delete entire row if cell contains specific value

    You're welcome. Glad to help out and thanks for the feedback. Please mark this thread as solved if you're satisfied with the solution given.

  8. #8
    Registered User
    Join Date
    03-25-2015
    Location
    Zagreb, Croatia
    MS-Off Ver
    Office 365
    Posts
    94

    Re: Macro - delete entire row if cell contains specific value

    Quote Originally Posted by Crispy85 View Post
    Could you post a sample workbook?
    thats not necessary, problem is solved.

    thank you very much!!

  9. #9
    Registered User
    Join Date
    03-25-2015
    Location
    Zagreb, Croatia
    MS-Off Ver
    Office 365
    Posts
    94

    Re: Macro - delete entire row if cell contains specific value

    I am sorry,

    obviously i did something wrong.
    i wrote down all the numbers when they are in column A i want to delete entire rows,
    but it doesnt work.
    can you tell me what i did wrong? it works, but only for two values that are on the top??

    Sub manduraz()
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 99810, xlOr, 99820
    Range("A2:A" & Range("A" & Rows.Count).End(3).Row).SpecialCells(12).EntireRow.Delete
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 99837
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 99838
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 99840
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 99841
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 99842
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 99844
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 99845
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 99846
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 99850
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 99885
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 295038
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 295039
    Range("A1:A" & Range("A" & Rows.Count).End(3).Row).AutoFilter 1, 295040
    Range("A2:A" & Range("A" & Rows.Count).End(3).Row).SpecialCells(12).EntireRow.Delete
    ActiveSheet.AutoFilterMode = False
    End Sub

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro - delete entire row if cell contains specific value

    Please take a moment to review the Forum Rules about posting code. Refer too Rule No. 3 about code tags.

    http://www.excelforum.com/forum-rule...rum-rules.html

    For your code after each time you filter, you would have to delete (see red). Otherwise you are just filtering the data. Try:

    Please Login or Register  to view this content.
    Last edited by JOHN H. DAVIS; 09-28-2016 at 11:28 AM.

  11. #11
    Registered User
    Join Date
    03-25-2015
    Location
    Zagreb, Croatia
    MS-Off Ver
    Office 365
    Posts
    94

    Re: Macro - delete entire row if cell contains specific value

    John H. Davis,

    sorry for breaking the rules! didnt know that. next time i will do it like according to the rules.

    the macro you wrote works perfectly!

    thank you very, very much for your help and patience!

    mandura

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro - delete entire row if cell contains specific value

    You're welcome. Glad to help out and thanks for the feedback.

+ 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. How to delete entire row if first cell of it is empty for specific range and worksheets
    By roshanvmech in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-01-2014, 12:36 PM
  2. Macro code to delete entire row if the cell in column C = 0
    By glock9mm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-18-2013, 02:50 PM
  3. Replies: 2
    Last Post: 01-15-2013, 02:55 AM
  4. Macro (Delete Entire row Cell in column R is empty)
    By andrewvt in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-20-2011, 07:06 AM
  5. Macro to delete entire row based on cell contents
    By ATX in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-06-2011, 03:52 AM
  6. macro to delete entire row based on TWO cell values
    By uncleslinky in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2011, 02:42 PM
  7. Delete entire row from A to F if cell A has specific content
    By vtech in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-02-2010, 06:01 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