Deleting Entire Rows based on content within a range of Columns.

Rusman8872

New Member
Joined
May 14, 2020
Messages
6
Office Version
  1. 2013
Platform
  1. Windows
Hello . Im working with a very large spreadsheet that I am mining out a small amount of data. In Columns Q thru T I have formulas that identify the data I don't need and then returns "Delete". I need some VBA code that will look in Rows Q through T and delete the entire row of any cell that contains "Delete". The sheet will always contain between 8k and 10k rows but never more that 10k.

I would appreciate any help that someone could help with some code to drop into my macro. I have tried to use a For\Next loop but am not able to get the syntax correct.
1589486751569.png

thanks
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi,
Check this out and let me know if that’s what you require.

VBA Code:
Sub RemoveRows()
    Dim LastRow&
    Dim i&, j&
   
    LastRow = Range("A1").CurrentRegion.Rows.Count
   
    If LastRow =1 then exit Sub

    For i = LastRow to 2 step -1
        For j = 12 to 15
            If LCase(Cells(i,j))= "delete"
                Rows(i).delete
                Exit For
            End if
        Next j
    Next i

    Msgbox "Done"
End sub
 
Upvote 0
thanks for your reply....its giving me a compile error i just cut and pasted it at the bottom of my existing code. I posted at the bottom of my existing code should i just run it as a separate macro and call it?
1589489247204.png
 
Upvote 0
This is another approach …

VBA Code:
Sub DeleteRows()

Dim a, b
With ActiveSheet
    a = .Range("Q1", .Range("T" & .UsedRange.Rows.Count))
    ReDim b(1 To UBound(a))
    For x = 2 To UBound(a)
        Select Case "Delete"
            Case a(x, 1), a(x, 2), a(x, 3), a(x, 4)
            b(x) = "delete"
        End Select
    Next
    .[U1].Resize(UBound(b)) = Application.Transpose(b)
    .Columns("U").AutoFilter 1, "delete"
    .UsedRange.Offset(1).SpecialCells(12).EntireRow.Delete
    .UsedRange.AutoFilter
End With

End Sub
 
Upvote 0
Dim a, b With ActiveSheet a = .Range("Q1", .Range("T" & .UsedRange.Rows.Count)) ReDim b(1 To UBound(a)) For x = 2 To UBound(a) Select Case "Delete" Case a(x, 1), a(x, 2), a(x, 3), a(x, 4) b(x) = "delete" End Select Next .[U1].Resize(UBound(b)) = Application.Transpose(b) .Columns("U").AutoFilter 1, "delete" .UsedRange.Offset(1).SpecialCells(12).EntireRow.Delete .UsedRange.AutoFilter End With
Thanks for your reply....this one gives me a runtime error:
1589491242281.png

1589491263549.png
 
Upvote 0
Do you have #N/A in your T:Q columns due to your formulas ? If yes, try to change them to anything else by using iferror() function then re-test the code again
 
Upvote 0
Do you have #N/A in your T:Q columns due to your formulas ? If yes, try to change them to anything else by using iferror() function then re-test the code again
That was the problem once i handled the #NA it worked perfectly....thanks you so much
 
Upvote 0

Forum statistics

Threads
1,215,513
Messages
6,125,258
Members
449,219
Latest member
daynle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top