Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi All:
hoping that someone can help. I am a newbie at vba only started a week ago. I wrote the following code but it gives me an incorrect result ie tax payable for persons with income greater than $30,000 per year. The problem seem to be in the case construction at the end of the script but I can't seem to sole it. Sub taxation5() TotalIncome = InputBox("Please enter Total Salary for January 2005") projectedsalary = TotalIncome * 12 MsgBox (" Your projected total income for 2005 will be " & Format(projectedsalary, "$#,##0.00")) Select Case projectedsalary Case Is <= 30000 personalallowance = 30000 Case Is 35000 personalallowance = 25000 Case 30001 To 35000 personalallowance = 30000 - (TotalIncome - 30000) End Select MsgBox ("your personal allowance for 2005 will be " & Format(personalallowance, "$#,##0.00")) Td1deductions = InputBox("Please enter other TD1 deductions for 2005 excluding personal allowance") chargeableincome = projectedsalary - personalallowance - Td1deductions If chargeableincome < 0 Then chargeableincome = 0 chargeableincome = MsgBox("Your chargeable income for the year will be " & Format(chargeableincome, "$#,##0.00") _ & " and no tax payable ") chargeableincome = MsgBox("Your chargeable income for the year will be " & Format(chargeableincome, "$#,##0.00")) Select Case chargeableincome Case 30000 To 50000 taxation = chargeableincome * 0.25 Case Is 50000 taxation = 12500 + (chargeableincome - 50000) * 0.3 End Select MsgBox (" Taxes of " & Format(taxation, "$#,##0.00") & " is tax payable to the Board of Inland Revenue") End If End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm a bit confused - is there really no tax for *chargeable* incomes
<30000, but if chargeable income is 50000, the portion <30000 is taxed?? This may get you started: Option Explicit Public Sub Taxation5a() Dim cTotalIncome As Currency Dim cProjectedSalary As Currency Dim cPersonalAllowance As Currency Dim cTD1Deductions As Currency Dim cChargeableIncome As Currency Dim cTaxation As Currency cTotalIncome = Application.InputBox( _ Prompt:="Please enter total salary for January 2005", _ Title:="Enter Salary", _ Default:=0, _ Type:=1) cProjectedSalary = cTotalIncome * 12# MsgBox Prompt:="Your projected total income for 2005 is " & _ Format(cProjectedSalary, "$#,##0.00") cPersonalAllowance = 25000 + Application.Min( _ Application.Max(0, (35000 - cProjectedSalary)), 5000) MsgBox Prompt:="Your personal allowance for 2005 will be " & _ Format(cPersonalAllowance, "$#,##0.00") cTD1Deductions = Application.InputBox( _ Prompt:="Please enter other TD1 deductions for " & _ "2005 excluding personal allowance", _ Title:="Enter TD1 Deductions", _ Default:=0, _ Type:=1) cChargeableIncome = Application.Max(0, _ cProjectedSalary - cPersonalAllowance - cTD1Deductions) cTaxation = cChargeableIncome * 0.25 + _ 0.05 * Application.Max(0, cChargeableIncome - 50000) MsgBox Prompt:="Your chargeable income for the year will be " & _ Format(cChargeableIncome, "$#,##0.00") & _ IIf(cChargeableIncome 0, "." & vbNewLine & "Taxes of " & _ Format(cTaxation, "$#,##0.00") & _ " are payable to the Board of Inland Revenue", _ ", and no tax payable") End Sub You may also be interested in a worksheet function solution: http://www.mcgimpsey.com/excel/variablerate.html In article .com, "PFL" wrote: Hi All: hoping that someone can help. I am a newbie at vba only started a week ago. I wrote the following code but it gives me an incorrect result ie tax payable for persons with income greater than $30,000 per year. The problem seem to be in the case construction at the end of the script but I can't seem to sole it. Sub taxation5() TotalIncome = InputBox("Please enter Total Salary for January 2005") projectedsalary = TotalIncome * 12 MsgBox (" Your projected total income for 2005 will be " & Format(projectedsalary, "$#,##0.00")) Select Case projectedsalary Case Is <= 30000 personalallowance = 30000 Case Is 35000 personalallowance = 25000 Case 30001 To 35000 personalallowance = 30000 - (TotalIncome - 30000) End Select MsgBox ("your personal allowance for 2005 will be " & Format(personalallowance, "$#,##0.00")) Td1deductions = InputBox("Please enter other TD1 deductions for 2005 excluding personal allowance") chargeableincome = projectedsalary - personalallowance - Td1deductions If chargeableincome < 0 Then chargeableincome = 0 chargeableincome = MsgBox("Your chargeable income for the year will be " & Format(chargeableincome, "$#,##0.00") _ & " and no tax payable ") chargeableincome = MsgBox("Your chargeable income for the year will be " & Format(chargeableincome, "$#,##0.00")) Select Case chargeableincome Case 30000 To 50000 taxation = chargeableincome * 0.25 Case Is 50000 taxation = 12500 + (chargeableincome - 50000) * 0.3 End Select MsgBox (" Taxes of " & Format(taxation, "$#,##0.00") & " is tax payable to the Board of Inland Revenue") End If End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks very much for your help it worked perfectly.
thanks again |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Case without Select Case error problem | Excel Discussion (Misc queries) | |||
Simplify Code - Select Case | Excel Programming | |||
2 x Case // Error why ? | Excel Programming | |||
Code for Case & Number format | Excel Programming | |||
Proper case code not working right | Excel Programming |