VBA to delete an entire row with #N/A

TheHack22

Board Regular
Joined
Feb 3, 2021
Messages
121
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi All,

I'm looking for some help with this line of code below. It's working fine, except for when there is NO "#N/A" in the dataset, it errors out when it cannot find #N/A to delete.
Can someone help me with this.? I think it needs something like, "If #N/A doesn't exist Sub". I don't know how this translates into VBA.

Sub DeleteNA()
Application.ScreenUpdating = False
Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Application.ScreenUpdating = True
End Sub



Imran
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try it this way...
VBA Code:
Sub DeleteNA()
  Application.ScreenUpdating = False
  On Error Resume Next
  Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
  On Error GoTo 0
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
You can just tell Excel to ignore any errors when running that line of code like this:
Rich (BB code):
Sub DeleteNA()
    Application.ScreenUpdating = False
    On Error Resume Next
    Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    On Error GoTo 0
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
You can just tell Excel to ignore any errors when running that line of code like this:
Rich (BB code):
Sub DeleteNA()
    Application.ScreenUpdating = False
    On Error Resume Next
    Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    On Error GoTo 0
    Application.ScreenUpdating = True
End Sub
@Joe4

Your note here was pretty helpful when I have these issues in the future("You can just tell Excel to ignore any errors when running that line of code like this:")

On Error Resume Next
Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
I do have some lines of codes that I can use this for. But I'll take @Rick Rothstein as the solution for this post- he posted his solution first :)

Thanks to both of you
Imran
 
Upvote 0
@Joe4

Your note here was pretty helpful when I have these issues in the future("You can just tell Excel to ignore any errors when running that line of code like this:")

On Error Resume Next
Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
I do have some lines of codes that I can use this for. But I'll take @Rick Rothstein as the solution for this post- he posted his solution first :)

Thanks to both of you
Imran
No problem! We basically posted the same solution, and he did beat me by a few seconds!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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