PC Review


Reply
Thread Tools Rate Thread

Can I simplify my Modules

 
 
Rayashe
Guest
Posts: n/a
 
      28th Apr 2008
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.
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      29th Apr 2008
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.

 
Reply With Quote
 
Rayashe
Guest
Posts: n/a
 
      29th Apr 2008
Thank you Joel

"Joel" wrote:

> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Public Variables, Class Modules and Standard Modules Excel Monkey Microsoft Excel Programming 2 30th Apr 2009 03:18 PM
Public, Private, Event modules, Forms modules,,, Jim May Microsoft Excel Programming 11 31st Oct 2005 03:12 AM
Basic question - modules and class modules - what's the difference? Mark Stephens Microsoft Excel Programming 9 8th May 2005 11:48 AM
Modules(index) and Modules("name") return different modules? Derek Boutang Microsoft Access VBA Modules 4 3rd Sep 2004 12:31 PM
Viewing modules on forms displays All form modules Clyde Ellingwood Microsoft Access Form Coding 0 24th Feb 2004 09:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:17 PM.