Quick question

bradyj7

Board Regular
Joined
Mar 2, 2011
Messages
106
Quick question,

Would the code below replace all #Div/0! errors with blanks in a worksheet?

Thank you

Code:
Sub DeleteErrors()
    ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas, 16).ClearContents
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Yes, but you can try this yourself - no?

It will clear all cells containing formulas that result in an error, not only because of dividing by 0.
 
Upvote 0
Hi there,

That is what I though it would do, but I cannot get it to work.

I'm calculating the average acceleration of a vehicle every 10 seconds as it travels along. However sometimes no acceleration occurs in that 10 second time period and hence the #DIV/0! error is returned to the cell.

I am inserting the average values into a new sheet so there are no formulas in the cells only values or #Div/0!. How can make it at the end replace all #Div/0! with blanks?

Thank you
Code:
Aavg = Application.Subtotal(1, Worksheets("raw").Range(Cells(sp, 7), Cells(ep, 7)))
    Worksheets("kinematic").Activate
    ActiveCell.Offset(0, 9).Value = Aavg
 
Upvote 0
Here's the trick...

It DOES indeed work, it just doesn't do what you think it does.

It replaces FORMULAS that result in error with blank..
Your cells don't contain formulas, they contain the result of your code that resulted in an error.

Instead of
ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas, 16).ClearContents

Try
ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants, 16).ClearContents

Hope that helps.
 
Upvote 0
Or even better, don't put the error in the cells in the first place...

Try this

Rich (BB code):
Aavg = Application.Subtotal(1, Worksheets("raw").Range(Cells(sp, 7), Cells(ep, 7)))
    Worksheets("kinematic").Activate
    If IsError(Aavg) Then
        'Do nothing
    Else
        ActiveCell.Offset(0, 9).Value = Aavg
    End If
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,282
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