The UDF just calculates the Allowed Deduction for that month using Total Deductions and 7 Discount fields.
Using the UDF is part of the worksheet
Just clearing the UDF from L2 should suffice, so I don't see any need to add a date condition
But, here it is anyway
Capture.JPG
Option Explicit
Function AllowedDeduction(DataMonth As Date, TotalDeduction As Range, TotalDues As Range, TotalDiscounts1 As Range, TotalDiscounts2 As Range) As Double
Dim dTotalDiscounts As Double, dNetSalary As Double, dFullDeduction As Double
If Year(Now) = Year(DataMonth) And Month(Now) = Month(DataMonth) Then
AllowedDeduction = 0#
Exit Function
End If
dTotalDiscounts = Application.WorksheetFunction.Sum(TotalDiscounts1) + Application.WorksheetFunction.Sum(TotalDiscounts2)
dNetSalary = TotalDues.Value - dTotalDiscounts
dFullDeduction = Round(0.25 * dNetSalary, 2)
If dFullDeduction <= TotalDeduction.Value Then
AllowedDeduction = dFullDeduction
Else
AllowedDeduction = TotalDeduction.Value
End If
End Function
Edit -- you may want to use this date logic instead
If DataMonth <= DateSerial(Year(Now), Month(Now), 1) Then
AllowedDeduction = 0#
Exit Function
End If