VBA: Tax Schedule: Making dynamic

Sparty

New Member
Joined
May 8, 2009
Messages
7
Hello folks, I'm new to VBA and need help making the following code dynamic:

Sub thisnthat()

Dim breakPoint
Dim taxPercent
Dim incomeAmount As Double
Dim taxAmount As Double
Dim rowCount As Integer
Dim lastRow As Long

incomeAmount = Round(Range("d4").Value)

Range("d4").Value = incomeAmount

With Worksheets("Model").Range("d4"<wbr>)
lastRow = Range(.Offset(0, 0), .End(xlDown)).Rows.Count

Do Until .Offset(rowCount, 0).Value = ""

Select Case incomeAmount 'check

Case Is > 75000 'check

taxAmount = incomeAmount * 0.3

Case Is = 75000 'check

taxAmount = incomeAmount * 0.25

Case Is >= 55000 'check

taxAmount = incomeAmount * 0.2

Case Is >= 35000 'check

taxAmount = incomeAmount * 0.15

Case Else

taxAmount = incomeAmount * 0

End Select 'check

Exit Do

rowCount = rowCount + 1

Loop
End With

Range("e4").Value = taxAmount

I've experimented with a few things but don't know enough to get the right syntax.

Below is the screenshot of what my code does (fills in cell E4 correctly- I want it to fill in all the gray squares, including if new income amounts are added to column D)

2cej601.png
 
Last edited:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I can't put the code together now, but this looks like a good case for a UDF -- User Defined Function. You would use it in every gray cell just like a regular Excel function, something like =TAX(D4, $A$4:$B$8), where D4 is the income and $A$4:$B$8 is the tax table range. You'd want absolute reference if you're going to copy the cell down the gray range. I hope this tip points you in the right direction.
 
Upvote 0
Thanks for the tip, looks like I asked a complicated question!

I have a simpler one if you (or someone) has the time. I'm trying to remember how to do vlookup and something isn't working out quite right.

These are the first few numbers in my array:

101747
1023643
1035093
1041752
1052723
106928
1074048
1081293
1093784
1106674

<tbody>
</tbody>


If the #s in B are > 1500 I'm trying to bring the numbers in column A & B over to a new tab in my spreadsheet. This is what I'm using so far that isn't working (data is the name of the tab with the information in it):

=IF(Data!$B4>1500,VLOOKUP(Data!$B4,Data!$A$4:$B$549,1,FALSE),"")
 
Last edited:
Upvote 0
Regarding post 1

Try

A
B
C
D
E
1
Breakpoint​
Tax​
Income​
Tax Amount​
2
15000​
0%​
112422​
33726,6​
3
35000​
15%​
48037​
7205,55​
4
55000​
20%​
19928​
0​
5
75000​
25%​
74482​
14896,4​
6
75000,01​
30%​
68543​
13708,6​
7
141486​
42445,8​
8
81066​
24319,8​

Formula in E2 copied down
=IF(D2<15000,0,D2*VLOOKUP(D2,A$2:B$6,2))

M.
 
Upvote 0
@Sparky, are you sure that your tax figure of 33727 is correct as tax rates in most countries is cumulative i.e. if you earned 40000 15000 would be 0 tax the next 20000 would get taxed at 15% and the remaining 5000 at 20%.
Your figure seems to tax the whole amount (including the zero rated threshold) at the top rate i.e. 112422 x 30%

For 112422 if it was cumulative it would break down to

Excel 2010 32 bit
B
C
13
20000​
3000​
14
20000​
4000​
15
20000​
5000​
16
37422​
11226.6​
17
Total
23226.6​
Sheet: Sheet4

The formula to work out the above using the table is as below...

Excel Workbook
ABCDE
1BreakpointTaxDiifferentialIncomeTax Amount
21500015%0.1511242223226.6
33500020%0.05480375607.4
45500025%0.0519928739.2
57500030%0.057448211870.5
66854310385.75
714148631945.8
88106613819.8
Sheet4
 
Last edited:
Upvote 0
Sorry should have tagged @Sparty not Sparky in the previous post.
Just while I am posting this I might as well post the formula if there was no lookup table which is...

=SUMPRODUCT(--(D2>{15000;35000;55000;75000}), (D2-{15000;35000;55000;75000}), {0.15;0.05;0.05;0.05})
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,812
Members
449,095
Latest member
m_smith_solihull

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