Public Function Claimed(QC, YA, OldRate, NewRate)
Application.Volatile True
'To find numeric AA and IA for special rates
''If IsNumeric(OldRate) = False Then
'' OldRate1 = Application.WorksheetFunction.VLookup(OldRate, Range("SRate"), 2, False)
'' IARate = Application.WorksheetFunction.VLookup(OldRate, Range("SRate"), 3, False) / 100
''Else
'' OldRate1 = OldRate
'' IARate = 0.2
''End If
''If IsNumeric(NewRate) = False Then
'' NewRate1 = Application.WorksheetFunction.VLookup(NewRate, Range("SRate"), 2, False)
'' IARate = Application.WorksheetFunction.VLookup(OldRate, Range("SRate"), 3, False) / 100
''Else
'' NewRate1 = NewRate
''End If
If Len(YA) = 0 And Len(NewRate) = 0 Then Exit Function
If IsNumeric(OldRate) = False Then
OldRate1 = Application.WorksheetFunction.VLookup(OldRate, Range("SRate"), 2, False)
IARate = Application.WorksheetFunction.VLookup(OldRate, Range("SRate"), 3, False) / 100
ElseIf YA = Sheet2.Range("C4") And ((OldRate1 = 100 And NewRate1 = 100)) Then
OldRate1 = OldRate
IARate = 0
ElseIf YA = Sheet2.Range("C4") And (OldRate1 = 50 And NewRate1 = 50) Then
OldRate1 = OldRate
IARate = 0
ElseIf YA <> Sheet2.Range("C4") And (OldRate1 = 50 And NewRate1 = 50) Then
OldRate1 = OldRate
IARate = 0
Else
OldRate1 = OldRate
IARate = 0.2
End If
If IsNumeric(NewRate) = False Then
NewRate1 = Application.WorksheetFunction.VLookup(NewRate, Range("SRate"), 2, False)
IARate = Application.WorksheetFunction.VLookup(OldRate, Range("SRate"), 3, False) / 100
ElseIf OldRate = 100 And NewRate = 100 Then
NewRate1 = NewRate
IARate = 0
ElseIf OldRate = 50 And NewRate = 50 Then
NewRate1 = NewRate
IARate = 0
ElseIf YA <> Sheet2.Range("C4") And (OldRate = 50 And NewRate = 50) Then
NewRate1 = NewRate
IARate = 0
Else
NewRate1 = NewRate
End If
'IA rate for IBA
If OldRate1 = 2 Or NewRate1 = 2 Or OldRate1 = 3 Or NewRate1 = 3 Then IARate = 0.1
'Lookup no. years allowance was claimed
If IsNumeric(YA) = True Then
If YA < 1950 Then
If YA <= 1 Then
NumYr = 0
Else
NumYr = 50 'To restrict no. of years allowance was claimed
End If
Else
NumYr = Application.WorksheetFunction.VLookup(YA, Range("YA_Tbl"), 2, False)
End If
Else
NumYr = Application.WorksheetFunction.VLookup(YA, Range("YA_Tbl"), 2, False)
End If
'Lookup no. years to 2000CYB
CYBYr = Application.WorksheetFunction.VLookup("2000C", Range("YA_Tbl"), 2, False)
'Lookup no. years to YA2002
NumYrB = Range("YrYA2002").Value
'To compute total % of AA claimed
If NewRate1 = 3 And OldRate = 2 Then
NewClaim = NewRate1 / 100 * NumYrB
OldClaim = OldRate1 / 100 * (NumYr - NumYrB)
ElseIf NewRate1 > 0 Then 'If NewRate is present
NewClaim = NewRate1 / 100 * CYBYr
OldClaim = OldRate1 / 100 * (NumYr - CYBYr)
Else
NewClaim = 0
OldClaim = OldRate1 / 100 * NumYr
End If
'TotalClaim = Round((NewClaim + OldClaim + IARate) * QC, 0)
If YA = Sheet2.Range("C4") And (OldRate = "A10" And NewRate = "A10") Then
TotalClaim = Round((0.1) * QC, 0)
ElseIf YA = Sheet2.Range("C4") And (OldRate = "A20" And NewRate = "A20") Then
TotalClaim = Round((0.2) * QC, 0)
ElseIf YA = Sheet2.Range("C4") And (OldRate = "A50" And NewRate = "A50") Then
TotalClaim = Round((0.5) * QC, 0)
ElseIf YA = Sheet2.Range("C4") And (OldRate = 100 And NewRate = 100) Then
TotalClaim = 0
ElseIf YA = Sheet2.Range("C4") And (OldRate = 50 And NewRate = 50) Then
TotalClaim = 0
Else
TotalClaim = Round((NewClaim + OldClaim + IARate) * QC, 0)
End If
Claimed = Application.WorksheetFunction.Min(TotalClaim, QC)
End Function