LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Can I simplify my Modules

Th eonly thing I would do different is not to hard code the term inside the
code but to pass it as a second parameter and then remove the definition of
Term inside the code

from
Function EerNI(salary)
to
Function EerNI(salary, Term)

delete
Term = Range("C5")



"Rayashe" wrote:

Hi. I am new to the VBA idea and am trying to learn. My Functions work fine,
but am I putting too much extra in that is not needed?
I have a sheet with C5 the contract term, C9 the total gross salary based on
contract term. Follows is my code to work out Employer NI, Tax, and Employee
NI based on the gross salary and the number of months (term):

Function EerNI(salary)
Const FreePay = 5435 'Per Year
Const Rate = 0.128
Dim Term As Integer
Term = Range("C5")
If salary (FreePay / 12 * Term) Then EerNI = (salary - (FreePay / 12 *
Term)) * Rate
End Function
Function Tax(salary)
Dim LowRate As Double, HighRate As Double
Dim Term As Integer
Dim FreePay As Double, UpperLimit As Double
FreePay = 5435 'Per Year
UpperLimit = 36000 'Per Year
LowRate = 0.2
HighRate = 0.4
Term = Range("C5")
FreePay = FreePay / 12 * Term
UpperLimit = UpperLimit / 12 * Term
If salary < FreePay Then Tax = 0
If (salary - FreePay - UpperLimit) UpperLimit Then Tax = UpperLimit *
LowRate _
+ (salary - FreePay - UpperLimit) * HighRate
If (salary - FreePay - UpperLimit) <= UpperLimit Then Tax = (salary -
FreePay) * LowRate
Tax = Round(Tax, 2)
End Function
Function NI(salary)
Dim Primary As Double, Upper As Double, UEL As Double
Primary = 453 'Per Month
Upper = 3337 'Per Month
UEL = Round((Upper - Primary) * 0.11, 2)
Term = Range("C5")
salary = Round(salary / Term, 2)
If salary < Primary Then NI = 0
If salary <= Upper Then NI = (salary - Primary) * 0.11
If salary Upper Then NI = (salary - Upper) * 0.01 + UEL
NI = NI * Term
End Function

Thanks.

 
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
Public, Private, Event modules, Forms modules,,, Jim May Excel Programming 11 October 31st 05 03:12 AM
Basic question - modules and class modules - what's the difference? Mark Stephens[_3_] Excel Programming 9 May 8th 05 11:48 AM
When to code in sheet or userform modules and when to use modules Tony James Excel Programming 1 December 16th 04 10:02 PM
please help simplify acarril[_10_] Excel Programming 1 September 21st 04 07:39 PM
Class Modules vs Modules Jeff Marshall Excel Programming 2 September 28th 03 07:57 PM


All times are GMT +1. The time now is 06:59 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"