Macro Clear all items containing #N/A

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I would like a macro to clear all items in Col E containing #N/A

your assistance in this regard is most appreciated
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Code:
sub test()
Dim LastRow,i as Long
LastRow = activesheet.range("E" & rows.count).end(xlup).row
for i = 1 to lastrow
if iserror(activesheet.range("E" & i)) = true then
activesheet.range("E" & i).clear
end if
next
end sub
 
Upvote 0
I would like a macro to clear all items in Col E containing #N/A
There may be a fast, non-looping way to do this, but a couple of questions first...

1) These #N/A values in Column E are all generated by formulas, correct?

2) Can there ever be any other errors in Column E besides #N/A errors?
 
Upvote 0
Thanks for the help, much appreciated

Rick, with regard to your question

1) These #N/A values in Column E are all generated by formulas

2) There are never any other errors in Column E besides #N/A errors


Regards

Howard
 
Upvote 0
simple way just replace using macro try below code

Code:
Sub Replace()

    Columns("E:E").Select
    Selection.Replace What:="#N/A", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    
End Sub
 
Upvote 0
Or

Code:
Sub test()
Columns("E").SpecialCells(xlCellTypeFormulas, xlErrors).ClearContents
End Sub
 
Upvote 0
Or you could add error handlers to the formulas, if you want to maintain the spreadsheet structure for future data.

Code:
Option Explicit
Sub AddIFERROR()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Dim xCell As Range
    Dim xFormula As String
    For Each xCell In Selection
        If xCell.HasFormula Then
            xFormula = Right(xCell.Formula, Len(xCell.Formula) - 1)
            xCell.Formula = "=IFERROR(" & xFormula & ","""")"
        End If
    Next xCell
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Guys

Thanks for all the input, much appreciated
 
Upvote 0

Forum statistics

Threads
1,214,421
Messages
6,119,392
Members
448,891
Latest member
tpierce

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