HI there - hoping someone can help. I am building a macro and in it I would like to delete all rows that have "DELETE ROW" in column AB. Sounds simple but I can't find a solution anywhere. Can anyone help? PLEASE!
HI there - hoping someone can help. I am building a macro and in it I would like to delete all rows that have "DELETE ROW" in column AB. Sounds simple but I can't find a solution anywhere. Can anyone help? PLEASE!
How about:
![]()
Sub del_row() Dim ws As Worksheet Dim lr As Long Set ws = ThisWorkbook.Worksheets("Sheet1") 'change sheet name as needed lr = ws.Range("A" & Rows.Count).End(xlUp).Row 'last row with data, using column A, change if needed ws.Range("AB1:AB" & lr).AutoFilter field:=1, Criteria1:="DELETE ROW" ws.Range("AB2:AB" & lr).SpecialCells(xlCellTypeVisible).EntireRow.Delete ws.AutoFilterMode = False End Sub
Last edited by Arkadi; 03-23-2018 at 02:29 PM. Reason: Changed the red 2, it used to be 1 but that deletes the header row.
Please help by:
Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know
There are 10 kinds of people in this world... those who understand binary, and those who don't.
I am not sure what I am doing wrong, this is how I have the macro into VBA
![]()
Sub del_row() Dim ws As Worksheet Dim lr As Long Sheets("B291-Inventory Report by Locati").Select lr = ws.Range("A" & Rows.Count).End(xlUp).Row ws.Range("AB1:AB" & lr).AutoFilter field:=1, Criteria1:="DELETE ROW" ws.Range("AB2:AB" & lr).SpecialCells(xlCellTypeVisible).EntireRow.Delete ws.AutoFilterMode = False End Sub
Last edited by jeffreybrown; 03-23-2018 at 02:54 PM. Reason: Please use code tags!
Or another option...
![]()
Sub FilterDelete() With Range("AB1", Range("AB" & Rows.Count).End(xlUp)) .AutoFilter Field:=1, Criteria1:="DELETE ROW" .Offset(1).EntireRow.Delete .AutoFilter End With End Sub
HTH
Regards, Jeff
jeffreybrown,
this worked - thank you so much!!!
Last edited by jeffreybrown; 03-23-2018 at 02:50 PM. Reason: Removed full quote
When you used my code, you activated the sheet, but did not set the WS object to the sheet, so "ws" in the code had no meaning. You simply needed
at the start.![]()
Set ws = ThisWorkbook.Worksheets("B291-Inventory Report by Locati")
Last edited by Arkadi; 03-23-2018 at 03:01 PM. Reason: Removed moderation request.
Thanks for fixing your post (#4)
If you are happy with the solution and the issue is resolved, please mark the thread as solved when you have a moment?
Thanks in advance, and happy coding
EDIT: I should also have taken a moment to say welcome to the forum! I believe you will find lots of people eager to be helpful when you have the need for it.
Last edited by Arkadi; 03-23-2018 at 03:06 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks