Help Creating Custom Function

sfsteve002

Board Regular
Joined
Apr 10, 2011
Messages
114
Hi, I'm trying to create the custom function below, but it does not work. I can't seem to figure out what I'm doing wrong. Can someone help?


Function SB1Calculation(Actual, Goal, OTV)

Dim Tier1 As Integer
Dim Tier2 As Integer
Dim Tier3 As Integer
Dim Tier4 As Integer
Dim SB1Calculation As Integer

Tier1 = (0.75 * OTV) / Goal

If Actual >= Goal Then
Tier2 = Max(Min(Actual - Goal, Goal * 1.15), 0) * (2 * ((0.75 * OTV) / Goal))
Else
Tier2 = 0
End If

If Actual >= Goal * 1.15 Then
Tier3 = Max(Min(((Actual - Goal) * 1.15), Goal * 0.15), 0) * (4 * ((0.75 * OTV) / Goal))
Else
Tier3 = 0
End If

If Actual > (2 * Goal) Then
Tier4 = (Actual - (2 * Goal)) * (0.75 * (OTV / Goal))
Else
Tier4 = 0
End If

SB1Commission = Tier1 + Tier2 + Tier3 + Tier4

End Function

Thanks,
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Code:
Function SB1Calculation(Actual As Currency, Goal As Currency, OTV As Currency) As Currency

Dim Tier1 As Integer
Dim Tier2 As Integer
Dim Tier3 As Integer
Dim Tier4 As Integer

    Tier1 = [0.75 * OTV] / [Goal]

If Actual >= Goal Then
    Tier2 = WorksheetFunction.Max(Worksheet.Min([Actual - Goal], [Goal * 1.15]), 0) * [2 * [[0.75 * OTV] / [Goal]]]
    Else
    Tier2 = 0
End If

If Actual >= Goal * 1.15 Then
    Tier3 = WorksheetFunction.Max(Worksheet.Min([Actual] - [Goal * 1.15], [Goal * 2] - [Goal * 1.15]), 0) * [4 * [[0.75 * OTV] / [Goal]]]
    Else
    Tier3 = 0
End If

If Actual > (2 * Goal) Then
    Tier4 = [Actual - [2 * Goal]] * [0.75 * [OTV / Goal]]
    Else
    Tier4 = 0
End If

SB1Calculation = Tier1 + Tier2 + Tier3 + Tier4

End Function
 
Upvote 0
I think you still need WorksheetFunction on Min as well:
Code:
WorksheetFunction.Max(Worksheet[B][COLOR=red]Function[/COLOR][/B].Min
 
Upvote 0
Still getting the #Value! error after the changes.

Code:
Function SB1Calculation(Actual As Currency, Goal As Currency, OTV As Currency) As Currency

Dim Tier1 As Integer
Dim Tier2 As Integer
Dim Tier3 As Integer
Dim Tier4 As Integer

    Tier1 = [0.75 * OTV] / [Goal]

If Actual >= Goal Then
    Tier2 = WorksheetFunction.Max(WorksheetFunction.Min([Actual - Goal], [Goal * 1.15]), 0) * [2 * [[0.75 * OTV] / [Goal]]]
    Else
    Tier2 = 0
End If

If Actual >= Goal * 1.15 Then
    Tier3 = WorksheetFunction.Max(WorksheetFunction.Min([Actual] - [Goal * 1.15], [Goal * 2] - [Goal * 1.15]), 0) * [4 * [[0.75 * OTV] / [Goal]]]
    Else
    Tier3 = 0
End If

If Actual > (2 * Goal) Then
    Tier4 = [Actual - [2 * Goal]] * [0.75 * [OTV / Goal]]
    Else
    Tier4 = 0
End If

SB1Calculation = Tier1 + Tier2 + Tier3 + Tier4

End Function
 
Upvote 0
Just use this:

Code:
Function SB1Calculation(Actual As Currency, Goal As Currency, OTV As Currency)
 
Dim Tier1 As Integer
Dim Tier2 As Integer
Dim Tier3 As Integer
Dim Tier4 As Integer
 
Tier1 = (0.75 * OTV) / Goal
 
If Actual >= Goal Then Tier2 = WorksheetFunction.Max(WorksheetFunction.Min(Actual - Goal, Goal * 1.15), 0) * (2 * ((0.75 * OTV) / Goal)) Else Tier2 = 0
If Actual >= Goal * 1.15 Then Tier3 = WorksheetFunction.Max(WorksheetFunction.Min(((Actual - Goal) * 1.15), Goal * 0.15), 0) * (4 * ((0.75 * OTV) / Goal)) Else Tier3 = 0
If Actual > (2 * Goal) Then Tier4 = (Actual - (2 * Goal)) * (0.75 * (OTV / Goal)) Else Tier4 = 0
 
SB1Calculation = Tier1 + Tier2 + Tier3 + Tier4
 
End Function
 
Upvote 0
I just tried it and I still getting the #Value! error.

Code:
Function SB3Calculation(Actual As Currency, Goal As Currency, OTV As Currency)
 
Dim Tier1 As Integer
Dim Tier2 As Integer
Dim Tier3 As Integer
Dim Tier4 As Integer
 
Tier1 = (0.75 * OTV) / Goal
 
If Actual >= Goal Then Tier2 = WorksheetFunction.Max(WorksheetFunction.Min(Actual - Goal, Goal * 1.15), 0) * (2 * ((0.75 * OTV) / Goal)) Else Tier2 = 0
If Actual >= Goal * 1.15 Then Tier3 = WorksheetFunction.Max(WorksheetFunction.Min(((Actual - Goal) * 1.15), Goal * 0.15), 0) * (4 * ((0.75 * OTV) / Goal)) Else Tier3 = 0
If Actual > (2 * Goal) Then Tier4 = (Actual - (2 * Goal)) * (0.75 * (OTV / Goal)) Else Tier4 = 0
 
SB3Calculation = Tier1 + Tier2 + Tier3 + Tier4
 
End Function
 
Upvote 0

Forum statistics

Threads
1,224,544
Messages
6,179,430
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