Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PFL PFL is offline
external usenet poster
 
Posts: 2
Default Error in code re case construction

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Error in code re case construction

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   Report Post  
Posted to microsoft.public.excel.programming
PFL PFL is offline
external usenet poster
 
Posts: 2
Default Error in code re case construction

Thanks very much for your help it worked perfectly.

thanks again

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
Simplify Code - Select Case Edgar Thoemmes[_4_] Excel Programming 1 January 19th 05 01:32 AM
2 x Case // Error why ? Philipp Oberleitner Excel Programming 7 June 26th 04 02:20 PM
Code for Case & Number format Bhuktar S[_3_] Excel Programming 1 April 23rd 04 10:56 AM
Proper case code not working right Juan Excel Programming 3 April 16th 04 11:11 PM


All times are GMT +1. The time now is 01:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"