Error Handling Custom Functions

WindsorKnot

Board Regular
Joined
Jan 4, 2009
Messages
160
Hi,

I need some help on error handling my function below. (I've only copied part of the function to keep it simple)

The function works fine, but if a tier is selected that isn't an option, the function returns a value of 0. Is there anyway to have the function return a #Value or #NA value if a valid tier is not selected?

Thanks.

Code:
Function HIGHPLAN(tier As String, Sal As Currency)
    Dim CONTRIB As Currency
    
    EEPERCENT = 0.022
    EE1PERCENT = 0.027
    EE2PERCENT = 0.034
    EE3PERCENT = 0.044
    
    Select Case tier
        Case Is = EE: Select Case EEPERCENT * Sal
                            Case 0 To 360: CONTRIB = 360
                            Case 360.01 To 1379.99: CONTRIB = EEPERCENT*Sal
                            Case Is >= 1380: CONTRIB = 1380
                            End Select
                            
        Case Is = EE1: Select Case EE1PERCENT * Sal
                            Case 0 To 720: CONTRIB = 720
                            Case 720.01 To 2759.99: CONTRIB =EE1PERCENT*Sal
                            Case Is >= 2760: CONTRIB = 2760
                        End Select
        End Select
       HIGHPLAN = CONTRIB
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Perhaps

Code:
If CONTRIB <> 0 Then
    HIGHPLAN = CONTRIB
Else
    HIGHPLAN = [#N/A]
End If
 
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,538
Members
449,316
Latest member
sravya

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