STEVEMILLS04
Board Regular
- Joined
- Oct 8, 2009
- Messages
- 113
Good morning/afternoon!
I am trying to create a button that will run a calculation for me based on a custom function. It keeps returning 0, which is my Case Else statement.
I debugged to make sure my data is in the appropriate columns. Hiredate is column J and Potential is column T.
Here is my button click code:
and here is my UDF with a case statement:
I am trying to create a button that will run a calculation for me based on a custom function. It keeps returning 0, which is my Case Else statement.
I debugged to make sure my data is in the appropriate columns. Hiredate is column J and Potential is column T.
Here is my button click code:
Code:
Private Sub CommandButton1_Click()
lastRow = 32 'Cells(Rows.Count, 21).End(xlUp).Row
For nRow = 15 To lastRow
Dim sDate As Date
sDate = Cells(nRow, 10)
Dim pBonus As Currency
pBonus = Cells(nRow, 20)
Cells(nRow, 21) = prbonus(sDate, pBonus)
Next nRow
End Sub
and here is my UDF with a case statement:
Code:
Function prbonus(HireDate As Date, Potential As Currency) As Currency
Dim result As Currency
Select Case HireDate
Case Month(HireDate) = 1 And Year(HireDate) = 2015
result = Potential * (11 / 12)
Case Month(HireDate) = 2 And Year(HireDate) = 2015
result = Potential * (10 / 12)
Case Month(HireDate) = 3 And Year(HireDate) = 2015
result = Potential * (9 / 12)
Case Month(HireDate) = 4 And Year(HireDate) = 2015
result = Potential * (8 / 12)
Case Month(HireDate) = 5 And Year(HireDate) = 2015
result = Potential * (7 / 12)
Case Month(HireDate) = 6 And Year(HireDate) = 2015
result = Potential * (6 / 12)
Case Month(HireDate) = 7 And Year(HireDate) = 2015
result = Potential * (5 / 12)
Case Month(HireDate) = 8 And Year(HireDate) = 2015
result = Potential * (4 / 12)
Case Month(HireDate) = 9 And Year(HireDate) = 2015
result = Potential * (3 / 12)
Case Month(HireDate) = 10 And Year(HireDate) = 2015
result = Potential * (2 / 12)
Case Month(HireDate) = 11 And Year(HireDate) = 2015
result = Potential * (1 / 12)
Case Month(HireDate) = 12 And Year(HireDate) = 2015
result = 0
Case Year(HireDate) < 2015
result = Potential
Case Else
result = 0
End Select
prbonus = result
End Function