Deleting #DIV/0! error

abberyfarm

Well-known Member
Joined
Aug 14, 2011
Messages
733
Hi there,

I use this code to delete #DIV/0! errors in my worksheet and it works fine
Code:
Sub DeleteErrors()
    ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants, 16).ClearContents
End Sub

However it will not work for column AX which as been calculated using a formula (= P/M).

Any ideas on how I can get it to work? I've tried this code but it will not work either
Code:
Sub Deleteax()
Worksheets("kinematic").Range("ax:ax").SpecialCells(xlCellTypeConstants, 16).ClearContents
End Sub
Thanks
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this:
Code:
Sub test()
If IsError(Range("A1").Value) Then
    errval = Range("A1").Value
    Select Case errval
        Case CVErr(xlErrDiv0)
          Range("A1").ClearContents
    End Select
End If
End Sub
 
Upvote 0
The first argument in the SpecialCells method should be set to Formulas:

Rich (BB code):
Worksheets("kinematic").Range("ax:ax").SpecialCells(xlCellTypeFormulas, 16).ClearContents
 
Upvote 0
Hi I used this code, for column AX, but it didn't work. Does this only check cell ax1, the errors can occur on any row in the column, it varies from time to time so I need to check the entire column.

Thanks
Code:
Sub test()
If IsError(Range("Ax1").Value) Then
    errval = Range("Ax1").Value
    Select Case errval
        Case CVErr(xlErrDiv0)
          Range("Ax1").ClearContents
    End Select
End If
End Sub
 
Upvote 0
Hi yes I do,

Here is the code for column ax

Code:
Lastrow = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Range("ax2:ax" & Lastrow).FormulaR1C1 = "=RC[-34]/RC[-37]"

Thanks
 
Upvote 0
Hi sorry for wasting your time,

I was calling the function before I even got to the that line in code!

Need to take a break!
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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