Hide Rows with #N/A error and change #NA values to 0

tempaccount

New Member
Joined
Aug 19, 2011
Messages
8
Hello everyone

I'm looking for a macro to hide all rows with a formula error with #N/A but before/after hiding I want to convert these #NA values to zero. Whatever other values in the row should still remain as is though except for the #NA values.

I found a similar thread which I will post below that has a similar case.
http://www.mrexcel.com/forum/showthread.php?t=527381

Thanks
 

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.
I'm looking for a macro to hide all rows with a formula error with #N/A but before/after hiding I want to convert these #NA values to zero.
Do you mean you want to replace the formulas with the numerical constant zero?
 
Upvote 0
Maybe like this

Code:
Sub atest()
With Sheets("Sheet1")
    On Error Resume Next
    With .UsedRange.SpecialCells(xlCellTypeFormulas, xlErrors)
        .Value = 0
        .EntireRow.Hidden = True
    On Error GoTo 0
End With
End Sub
 
Upvote 0
Yes Rick, I forgot to specify that I wanted it to be numerical not text value. And I tried the above macro but it gave me a debug error saying "Expected End With"
 
Upvote 0
Maybe like this

Rich (BB code):
Sub atest()
    With Sheets("Sheet1")
        On Error Resume Next
        With .UsedRange.SpecialCells(xlCellTypeFormulas, xlErrors)
            .Value = 0
            .EntireRow.Hidden = True
        End With
        On Error GoTo 0
    End With
End Sub
You accidentally omitted the End With statement I show in red above.

Also, just to point out for the OP in case it matters, the code you posted will replace all cells displaying an error with 0, not just the #N/A ones.
 
Upvote 0
Oops!

Rich (BB code):
Sub atest()
With Sheets("Sheet1")
    On Error Resume Next
    With .UsedRange.SpecialCells(xlCellTypeFormulas, xlErrors)
        .Value = 0
        .EntireRow.Hidden = True
    End With
    On Error GoTo 0
End With
End Sub
 
Upvote 0
Unfortunately it does matter :(. I need to sum up the column of vlookup formulas and they are associated with names that I need for future years. When the vlookups show the N/A error they will cause a chain reaction and effect other formulas in the sheet like sum & percent formulas.

edit: Silly me, I forgot to mention that I have a macro that paste specials these values as a text value format. So the macro needs to be ran after this process. Hopefully that makes it simpler.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,691
Members
452,938
Latest member
babeneker

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