How to get macro to continue

bradyj7

Board Regular
Joined
Mar 2, 2011
Messages
106
Hi there,

I'm calculating the standard deviation of deceleration of a vehicle. I do this by filtering out cells with positive acceleration. However sometimes there is no deceleration in that range of cells, so no cells can be found and the macro stops. How can I make it return "No deceleration" and continue on? Or even just the error #DIV/0! and continue on?

Thank you

Code:
'Standard deviation Deccceleration

    Worksheets("raw").Select
    With ActiveSheet

            .AutoFilterMode = False
            .Range("a1:j1").AutoFilter
            .Range("a1:j1").AutoFilter field:=7, Criteria1:="<0"  'only display cases of deacc
    End With

    
    StandardDevDeacc = Application.StDev(Worksheets("raw").Range(Cells(sp, 7), Cells(ep, 7)).SpecialCells(xlCellTypeVisible))
    Worksheets("kinematic").Activate
    ActiveCell.Offset(0, 17).Value = StandardDevDeacc
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this I don't have the full context of your sub but this should work.

Code:
'Standard deviation Deccceleration
    Dim DeaccRng As Range
    
    Worksheets("raw").Select
    With ActiveSheet

            .AutoFilterMode = False
            .Range("a1:j1").AutoFilter
            .Range("a1:j1").AutoFilter field:=7, Criteria1:="<0"  'only display cases of deacc
    End With
    On Error Resume Next
    Set DeaccRng = Worksheets("raw").Range(Cells(sp, 7), Cells(ep, 7)).SpecialCells(xlCellTypeVisible)
    On Error GoTo 0
    '// Check if the range has been defined
    If Not DeaccRng Is Nothing Then
        StandardDevDeacc = Application.StDev(DeaccRng)
    Else
        StandardDevDeacc = "No Deccceleration Values"
    End If
    Worksheets("kinematic").Activate
    ActiveCell.Offset(0, 17).Value = StandardDevDeacc
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,445
Members
452,915
Latest member
hannnahheileen

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