VBA to clear contents of entire row if cell=#n/a

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
210
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
To be clear, I do not want to delete the entire row, I just want to clear the contents of the entire row if there is cell in that row that contains #n/a. Is this possible?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Please show us a sample of what your data looks like. Use XL2BB to upload that sample.
 
Upvote 0
Please show us a sample of what your data looks like. Use XL2BB to upload that sample.

So in this example, because it contains #N/A, I would like to just CLEAR row contents and leave it as a blank row, not DELETE the row. Can you help? Thank you.

Dog NameDog typeType of requestReference ID #ClientLocationCostAccountCVV Code
#N/A#N/A#N/A2123456500
 
Upvote 0
1. Do those #N/A cells contain formulas or are they text values?

2. Is there likely to be any other error values on the sheet (eg #VALUE!, #DIV/0! etc)?
 
Upvote 0
1. Do those #N/A cells contain formulas or are they text values?

2. Is there likely to be any other error values on the sheet (eg #VALUE!, #DIV/0! etc)?
Hello Peter. Please see answers to your questions below.
1. Yes, it contains a formula, but returns #N/A because there is not enough data provided for that cell to calculate, hence, the reason to clear the row.
2. Only #N/A rows will be cleared. It will not contain any other error values in the row.
Thank you.
 
Upvote 0
In that case try this with a copy of your workbook.

VBA Code:
Sub Clear_NA_Rows()
  ActiveSheet.UsedRange.SpecialCells(xlFormulas, xlErrors).EntireRow.ClearContents
End Sub
 
Upvote 0
If its a formula, then look within the formula for an "#N/A" and change it to blank "". For example:

Look for #N/A:
Excel Formula:
=iferror("My Formula","#N/A")

Change to:
Excel Formula:
=iferror("My Formula","")
 
Upvote 0
In that case try this with a copy of your workbook.

VBA Code:
Sub Clear_NA_Rows()
  ActiveSheet.UsedRange.SpecialCells(xlFormulas, xlErrors).EntireRow.ClearContents
End Sub
Thank you Peter_SSs. That's exactly what I wanted. Works prefectly!!
 
Upvote 0

Forum statistics

Threads
1,215,518
Messages
6,125,291
Members
449,218
Latest member
Excel Master

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