VBA IFError Function?

JakeVBA2009

New Member
Joined
Nov 30, 2009
Messages
16
Hi guys, I need to write an IFError Function that closely mimics the Excel 2007 IFError Function.

(It does not need to consider the case of the function being used as part of an array formula)

I've got this code, but feel like i'm barking up the wrong tree completely...

Thanks in advance.

Sub openVBADocument()
Dim strFolder As String
Dim strVBADocument As String

strFolder = Range("Folder")
strVBADocument = Range("VBADocument")
If Dir("VBA Document" & strFolder & "\" & strVBADocument & ".xls") = "" Then
MsgBox "Error", vbExclamation
Else
Workbooks.Open Filename:="VBA Document" & strFolder & "\" & strVBADocument & ".xls"
End If
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Ahh ok, so i'm trying this formula but it doesnt seem to work

=IFERR(SUM(A5+B5),"Not Found")

Whats the problem there?

My Function is called IFERR and its displayed on the function list...
 
Upvote 0
If you changed the name of the function to IFERR, you ALSO need to change the other references to IFERROR in the rest of the code to IFERR

In the code below, If you change the name of the funtion, you need to change all HIGHLIGHTED lines need to be the same...
Rich (BB code):
Function IFError(Formula As Variant, Show As String)
On Error GoTo ErrorHandler
If IsError(Formula) Then
 IFError = Show
Else
 IFError = Formula
End If
 
Exit Function
 
ErrorHandler:
Resume Next
 
End Function
 
Upvote 0
Function IFERR(Formula As Variant, Show As String)
On Error GoTo ErrorHandler
If IsError(Formula) Then
IFERR = Show
Else
IFERR = Formula
End If

Exit Function

ErrorHandler:
Resume Next

End Function

Yeah, i changed it where necessary anyway.

Everytime i insert the function in the formula tab, it asks me to select function arguements. Do i need to set these in concrete somehow? Or will it always ask me to define function arguements before i run the function?
 
Upvote 0
Excel Workbook
AB
310
4Test
555
605
Sheet1
Excel 2007
Cell Formulas
RangeFormula
B3=IFERR(SUM(A5+B5),"Test")
B4=IFERR(B6/A6,"Test")
 
Upvote 0
So where do you type in the Formula in order to test it out?

In a cell on your sheet.


Do i need to set these in concrete somehow? Or will it always ask me to define function arguements before i run the function?

Yes, that's the whole Idea.

You're creating your own function. Designed to do what XL2007's IFERROR function does.
so you write the formula in a cell..
=IFERR(theformulayouwanttotestforerror,whatitshouldshowifitisanerror)
 
Upvote 0
Worksheet Formulas
Cell Formula
B3 =IFERR(SUM(A5+B5),"Test")
B4 =IFERR(B6/A6,"Test")

I'm not quite sure I understand your question. In order this is what I did
1) Copied in code in new module
2) in cell a5 I typed 5
3) in cell b5 I typed 5
4) in cell a6 I typed 0
5) in cell b6 I typed 5
6) in cell B3 I typed: =IFERR(SUM(A5+B5),"Test")
7) in cell b4 I typed : =IFERR(B6/A6,"Test")
 
Upvote 0

Forum statistics

Threads
1,215,174
Messages
6,123,451
Members
449,100
Latest member
sktz

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