Delete N/A

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I would like to delete #N/A in Col U from row 2 onwards


I have written code to do this, but cannot get the macro to delete these


Code:
 Sub Delete_Unwanted_Data()

Sheets("Creditors Paid").Select

Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
 If Range("U" & i) = "#N/A" Then EntireRow.Delete
     
Next i
End Sub


It would be appreciated if someone could kindly assist me
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try this.
Code:
Sub Delete_Unwanted_Data()
Dim LR As Long, i As Long

    Sheets("Creditors Paid").Select

    LR = Range("A" & Rows.Count).End(xlUp).Row

    For i = LR To 2 Step -1
        If Range("U" & i) = "#N/A" Then Rows(i).Delete     
    Next i

End Sub
 
Upvote 0
You have formulas in Column U, correct? If so, and assuming #N/A is the only errors you have displayed in Column U, then give this macro a try...
Code:
Sub Delete_Unwanted_Data()
  Columns("U").SpecialCells(xlFormulas, xlErrors).EntireRow.Delete
End Sub
 
Last edited:
Upvote 0
Hi Norie


Thanks for the help


I get type mismatch when running the code and the following is highlighted

Code:
 If Range("U" & i) = "#N/A" Then Rows(i).Delete


Kindly check & amend
 
Upvote 0
@howard,

Our messages crossed in the ether at about the same time, so you may not have noticed what I posted in Message #3 ... you might find it interesting.
 
Upvote 0
Oops, missed an important part of the code.

Try this.
Code:
Sub Delete_Unwanted_Data()
Dim LR As Long, i As Long

    Sheets("Creditors Paid").Select

    LR = Range("A" & Rows.Count).End(xlUp).Row

    For i = LR To 2 Step -1
        If Range("U" & i).Text = "#N/A" Then Rows(i).Delete     
    Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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