私はこのコーディングプロジェクトに非常に行き詰まっており、本当に助けが必要です.
個人の所得に対する税金を計算するコードを書こうとしています。このモデルでは、私の教授が、使用する税率のリストと、税金の計算方法を変更する一連のルールを提供してくれました。私はこれに何時間も取り組んできましたが、正しい答えを得ることができません。
この関数は Excel でエラーを返しますが、その#VALUE
理由がわかりません。
'This function calculate the tax liability based on taxable income (AGI)
Function CalculateTax(taxableIncome As Variant, taxRates As Variant, _
taxThresholds As Variant, standardDeduction As Variant, _
personalException As Variant, AlternativeTaxSystem As Variant, _
bequest As Variant) As Variant
'Initiate a variable to use to determine the size of taxRates - for some reason doing this directly doesn't work
Dim sizeArray As Variant
sizeArray = taxRates
'Initiate a variable for the alternative tax system
Dim AltTaxRate As Double
AltTaxRate = taxRates(i) - 0.05
'Initiate variable and calculate amount to apply to tax table, leaving out the deductions from the equation
Dim amountToTax As Double
amountToTax = taxableIncome
'Initiate tax amount and set to zero
Dim taxAmount As Double
taxAmount = 0
'loop over tax brackets, adding the incremental tax each time
For i = 1 To UBound(sizeArray, 1)
'Runs an if statement to check if all three conditions are met
If AlternativeTaxSystem = "Yes" And bequest = "No" And taxRates(i) >= 0.2 Then
'Calculate the tax amount per bracket, based on the minimum of the bracket size or total tax minus the bracket threshold, with a true minimum at zero, and subtracting off 0.05 from the tax rates
taxAmount = taxAmount + Application.Max(Application.Min(taxThresholds(i + 1) - taxThresholds(i), amountToTax - taxThresholds(i)), 0) * AltTaxRate
ElseIf AlternativeTaxSystem = "Yes" And bequest = "No" And taxRates(i) < 0.2 Then
taxAmount = taxAmount + Application.Max(Application.Min(taxThresholds(i + 1) - taxThresholds(i), amountToTax - taxThresholds(i)), 0) * taxRates(i)
ElseIf AlternativeTaxSystem = "Yes" And bequest = "Yes" And taxRates(i) >= 0.2 Then
amountToTax = taxableIncome - 250000
taxAmount = taxAmount + Application.Max(Application.Min(taxThresholds(i + 1) - taxThresholds(i), amountToTax - taxThresholds(i)), 0) * AltTaxRate
ElseIf AlternativeTaxSystem = "Yes" And bequest = "Yes" And taxRates(i) < 0.2 Then
amountToTax = taxableIncome - 250000
taxAmount = taxAmount + Application.Max(Application.Min(taxThresholds(i + 1) - taxThresholds(i), amountToTax - taxThresholds(i)), 0) * taxRates(i)
Else
amountToTax = taxableIncome - standardDeduction - personalException
taxAmount = taxAmount + Application.Max(Application.Min(taxThresholds(i + 1) - taxThresholds(i), amountToTax - taxThresholds(i)), 0) * taxRates(i)
End If
Next i
'output answer to function
CalculateTax = taxAmount
End Function