Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / April 2008

Tip: Looking for answers? Try searching our database.

Can I simplify my Modules

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rayashe - 28 Apr 2008 22:10 GMT
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.
Joel - 29 Apr 2008 05:34 GMT
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")

> 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?
[quoted text clipped - 43 lines]
>
> Thanks.
Rayashe - 29 Apr 2008 09:38 GMT
Thank you Joel

> 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
[quoted text clipped - 55 lines]
> >
> > Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.