Trying to Delete Multiple Rows at Once

JADownie

Active Member
Joined
Dec 11, 2007
Messages
395
I am trying to delete rows where Col F = 0 or #N/A

I am getting a runtime error here now, but can't figure out exactly why yet....


Sub DPNext()

Dim LastRow As Long, x As Long

Range("A3:F22").Select

LastRow = Cells(Rows.Count, "F").End(xlUp).Row

For x = LastRow To 1 Step -1
If UCase(Cells(x, 6).Value) = "#N/A" Or _
UCase(Cells(x, 6).Value) = "0" Then

Rows(x).Delete

End If
Next
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Is that "#N/A" a hard-coded value, or the "#N/A" error being returned by a formula?
 
Upvote 0
Is that is the #N/A error resulting from a formula (like VLOOLKUP), try this:
VBA Code:
Sub DPNext()

Dim LastRow As Long, x As Long

LastRow = Cells(Rows.Count, "F").End(xlUp).Row

For x = LastRow To 1 Step -1
    If Application.WorksheetFunction.IsNA(Cells(x, 6)) Then
        Rows(x).Delete
    Else
        If Cells(x, 6) = 0 Then Rows(x).Delete
    End If
Next x

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,440
Messages
6,124,882
Members
449,193
Latest member
PurplePlop

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