|
|
Question : Adding to a formula with VBA
|
|
Hi,
I have a large range of formulae that I would like to error trap:
ie add IF(ISERROR(.....
If there is an error I want the cell to return "-" eg
=IF(ISERROR(A1/B1),"-",A1/B1)
How can I create this from the basic =A1/B1
I've started with the following but can't think (it's Friday afternoon!!) how to manipulate the formula correctly:
Sub IFISERROR()
Dim cel As Object Dim val
For Each cel In Selection Application.StatusBar = cel.Address If Left(cel.Value, 1) = "=" Then cel.Formula = 'What should I put here?? End If Next cel Application.StatusBar = False End Sub
Best Regards Darren
|
Answer : Adding to a formula with VBA
|
|
Actually you can test for aformula directly by using
If cel.HasFormula Then
Be careful to only run this routine once or it will start nesting the IF(ISERROR( entries. You could test for that as well and ignore if already present I guess
|
|
|
|