I am trying to write a macro that puts =Iferror at the beginning of a formula, if it is not already there. I have created a macro that almost does this. The problems is that it does not work if the selection is greater than one cell. The code is shown below. Thanks!


Sub IfError()
Dim Lefty

For Each cell In Selection
    
    Lefty = Left(Selection.Formula, 8)
    
    If Lefty <> "=IFERROR" Then
    
    cell.Formula = "=IFERROR(" & Right$(cell.Formula, Len(cell.Formula) - 1) & ",0)"
        
    End If
    
    Next cell

End Sub