excel中使用vba制作个人所得税计算器
1、首先我们打开一个工作样表作为例子。
2、打开vba编辑窗口,使用alt+f11组合快捷键,或是使用开发者工具标签下的vb快捷按钮。并插入一个新的模块。
3、在模块编辑窗口中输入一个函数代码,代码如下:
Function 个人所得税()
curP = curP - 1600 '1600为免征额
If curP > 0 Then
Select Case curP
Case Is <= 500
suo = curP * 0.05
Case Is <= 2000
suo = (curP - 500) * 0.1 + 25
Case Is <= 5000
suo = (curP - 2000) * 0.15 + 125
Case Is <= 20000
suo = (curP - 5000) * 0.2 + 375
Case Is <= 40000
suo = (curP - 20000) * 0.25 + 1375
Case Is < 60000
suo = (curP - 40000) * 0.3 + 3375
Case Is < 80000
suo = (curP - 60000) * 0.35 + 6375
Case Is < 100000
suo = (curP - 80000) * 0.4 + 10375
Case Else
suo = (curP - 100000) * 0.45 + 15375
End Select
个人所得税 = suo
Else
个人所得税 = 0
End If
End Function
4、分析一下代码是主要是每个随征额的确定,是工资收入越大,则征税比例越高,所以我们需要对工资额进行判定。如果使用if函数则在条件处理上会写的很繁琐,比如这样:
if suo<500 then shuie =curP * 0.05
elseif suo <=2000 and suo > 500 then shuie =(curP - 500) * 0.1 + 25
....
end if
这样写就会很麻烦。
新闻热点
疑难解答