税率在Excel VBA
下面我们就来看看在Excel VBA程序,计算上的收入税。以下税率适用于个人谁是澳大利亚的居民。
Taxable income | Tax on this income |
---|---|
0 – $6,000 |
Nil |
$6,001 – $35,000 |
15c for each $1 over $6,000 |
$35,001 – $80,000 |
$4,350 plus 30c for each $1 over $35,000 |
$80,001 – $180,000 |
$17,850 plus 38c for each $1 over $80,000 |
$180,001 and over |
$55,850 plus 45c for each $1 over $180,000 |
现状:
1.首先,我们声明两个double变量。一个双变量我们称之为收入,我们称之为税一个双变量。
Dim income As Double Dim tax As Double
2.我们初始化变量收入与单元格A2的价值和圆形它。
income = Round(Range("A2").Value)
3.我们再次下修约值到单元格A2。
Range("A2").Value = income
选择案例声明来计算收入的征税。 Excel VBA中使用的收入来测试每个后续的Case语句,看是否Case语句下的代码应该被执行。
Select Case income Case Is >= 180001 tax = 55850 + 0.45 (income - 180000) Case Is >= 80001 tax = 17850 + 0.38 (income - 80000) Case Is >= 35001 tax = 4350 + 0.3 (income - 35000) Case Is >= 6001 tax = 0.15 (income - 6000) Case Else tax = 0 End Select
例如:如果收入37000,税等于4350 + 0.3 *(37000-35000)= 4350 + 600 = $ 4950 5.我们写可变税细胞B2的值。
Range("B2").Value = tax
6.将这个代码在一个命令按钮并进行测试。
结果: