VBA to delete an entire row with #N/A

TheHack22

Board Regular
Joined
Feb 3, 2021
Messages
111
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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,034
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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
 
Solution

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
65,459
Office Version
  1. 365
Platform
  1. Windows
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
 

TheHack22

Board Regular
Joined
Feb 3, 2021
Messages
111
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
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
@Rick Rothstein

Thanks a million. This works well. :)

Imran
 

TheHack22

Board Regular
Joined
Feb 3, 2021
Messages
111
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
65,459
Office Version
  1. 365
Platform
  1. Windows
@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!
 

Forum statistics

Threads
1,175,753
Messages
5,899,280
Members
434,759
Latest member
carcharoth

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
Top