Please critique this tax calculation UDF

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,525
Office Version
  1. 365
Platform
  1. Windows
I would appreciate any comments on this UDF to calculate taxes. Once I am sure that it is working, I will move the constants (brackets and rates) to the calling sheet and pass them to the UDF. I'll also have the calling sheet calculate the cumulative maximum taxes for each bracket, so the UDF doesn't have to do it over and over.

VBA Code:
Function TaxCalc(pIncome As Double) As Double

Dim BracketTop(0 To 7) As Double  'The upper end of the brackets
Dim BracketWid(1 To 6) As Double  'The width of each bracket
Dim Rate(1 To 7) As Double        'The tax rates in each bracket

' Bracket constants. Move these to the sheet and pass them as a range
BracketTop(0) = 0
BracketTop(1) = 10000:  Rate(1) = 0.1   '10% in bracket 1
BracketTop(2) = 40000:  Rate(2) = 0.12  '12% in bracket 2
BracketTop(3) = 86000:  Rate(3) = 0.22  '22% in bracket 3
BracketTop(4) = 165000: Rate(4) = 0.24  '24% in bracket 4
BracketTop(5) = 209000: Rate(5) = 0.32  '32% in bracket 5
BracketTop(6) = 524000: Rate(6) = 0.35  '35% in bracket 6
BracketTop(7) = 0:      Rate(7) = 0.37  '37% in bracket 7

'The cumulative maximum taxes. Do this in the sheet, too
Dim CumTax(0 To 6) As Double
CumTax(0) = 0
Dim iLoop As Long
For iLoop = 1 To 7
  If iLoop = 7 Or pIncome <= BracketTop(iLoop) Then
    TaxCalc = CumTax(iLoop - 1) + (pIncome - BracketTop(iLoop - 1)) * Rate(iLoop)
    Exit For
  End If
  BracketWid(iLoop) = BracketTop(iLoop) - BracketTop(iLoop - 1)
  CumTax(iLoop) = CumTax(iLoop - 1) + BracketWid(iLoop) * Rate(iLoop)
Next iLoop

End Function

Here's a minisheet calling it.

Wages by Profession.xlsx
CDE
3Gross IncomeTaxes%
4$0.00$0.00#DIV/0!
5$1,000.00$100.0010.00%
6$10,000.00$1,000.0010.00%
7$11,000.00$1,120.0010.18%
8$20,000.00$2,200.0011.00%
9$40,000.00$4,600.0011.50%
10$86,000.00$14,720.0017.12%
11$165,000.00$33,680.0020.41%
12$209,000.00$47,760.0022.85%
13$524,000.00$158,010.0030.15%
14$1,000,000.00$334,130.0033.41%
15$5,000,000.00$1,814,130.0036.28%
Sheet5
Cell Formulas
RangeFormula
D4:D15D4=taxcalc(C4)
E4:E15E4=[@Taxes]/[@[Gross Income]]


Thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I have replaced the code that calculates the tax bracket information with a table in the calling sheet. The UDF code is now simpler.

VBA Code:
Function TaxCalc(pIncome As Double, pBrackets As Range) As Double

' Define the columns in the tax bracket table (pBrackets)
Const iTop As Long = 2      'Column 2: Top incomes
Const iRate As Long = 3     'Column 3: Tax rates
' Column 4, bracket width, is not used here
Const iCumTax As Long = 5   'Column 5: Cum taxes

Dim iLoop As Long       'Loop index
For iLoop = 2 To 8      'Bracket 1 is in row 2
  'If we are in the top bracket or the income is within this bracket,
  '.calculate the tax and exit
  If iLoop = 8 Or pIncome <= pBrackets(iLoop, iTop) Then
    TaxCalc = pBrackets(iLoop - 1, iCumTax) _
            + (pIncome - pBrackets(iLoop - 1, iTop)) * pBrackets(iLoop, iRate)
    Exit For
  End If
Next iLoop

End Function

And here's a minisheet using it.

Wages by Profession.xlsx
CDEFGHIJK
3Gross IncomeTaxes%#TopRateWidthCum Tax
4$0.00$0.00#DIV/0!0$00.00%--$0
5$1,000.00$100.0010.00%1$10,00010.00%$10,000$1,000
6$10,000.00$1,000.0010.00%2$40,00012.00%$30,000$4,600
7$11,000.00$1,120.0010.18%3$86,00022.00%$46,000$14,720
8$20,000.00$2,200.0011.00%4$165,00024.00%$79,000$33,680
9$40,000.00$4,600.0011.50%5$209,00032.00%$44,000$47,760
10$86,000.00$14,720.0017.12%6$524,00035.00%$315,000$158,010
11$165,000.00$33,680.0020.41%7--37.00%--
12$209,000.00$47,760.0022.85%
13$524,000.00$158,010.0030.15%
14$1,000,000.00$334,130.0033.41%
15$5,000,000.00$1,814,130.0036.28%
Tax Brackets
Cell Formulas
RangeFormula
D4:D15D4=taxcalc(C4,TaxBrackets)
E4:E15E4=[@Taxes]/[@[Gross Income]]
J5:J10J5=[@Top]-H4
K5:K10K5=K4+[@Width]*[@Rate]
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,649
Members
448,975
Latest member
sweeberry

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