Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Scope of private function in VBA Module

A function declared Private in VBA Module doesn't run on UserForm. Error
reads: Sub or Function not defined.

Function:
Private Function IncomeTax(salaryGross, children, spouse) As Double
Application.ScreenUpdating = False
Call objectVarDeclare

Dim dblChildAmount As Double
Dim dblSpouseAmount As Double
Dim dblTaxAmount As Double
Dim dblTaxNet As Double
Dim rngTaxOne As Single
Set rngTaxOne = salarios_data.Range("tax1")
Dim rngTaxTwo As Single
Set rngTaxTwo = salarios_data.Range("tax2")
Dim rngMinSalary As Range
Set rngMinSalary = salariosData.Range("upper_first")
Dim rngFirstTier As Range
Set rngFirstTier = salarios_data.Range("upper_second")
Dim rngChildCredit As Range
Set rngChildCredit =
salarios_data.Range("child_credit")
Dim rngSpouseCredit As Range
Set rngSpouseCredit = salarios_data.Range("spouse_credit")

dblChildAmount = 0
dblSpouseAmount = 0
dblTaxAmount = 0
If salaryGross <= minSalary Then
dblTaxAmount = 0
IncomeTax = 0
dblChildAmount = 0
dblSpouse_amount = 0
ElseIf salaryGross minSalary And salaryGross <= rngFirstTier Then
dblTaxAmount = ((salaryGross - minSalary) * rngTaxOne.Value)
Select Case children
Case Is 0
dblChildAmount = children * rngChildCredit
Case Is = 0
dblChildAmount = 0
End Select
Select Case spouse
Case Is 0
dblSpouseAmount = spouse * rngSpouseCredit
Case Is = 0
dblSpouseAmount = 0
End Select
If dblChildAmount + dblSpouseAmount = dblTaxAmount
Then
IncomeTax = 0
Else: IncomeTax = dblTaxAmount - dblChildAmount - _
dblSpouseAmount
End If
ElseIf salaryGross rngFirstTier Then
dblTaxAmount = ((rngFirstTier - rngMinSalary) * rngTaxOne.Value) + _
((salario - rngFirstTier) * rngTaxTwo.Value)
Select Case children
Case Is 0
dblChildAmount = children * rngChildCredit
Case Is = 0
dblChildAmount = 0
End Select
Select Case spouse
Case Is 0
dblSpouseAmount = spouse * rngSpouseCredit
Case Is = 0
dblSpouseAmount = 0
End Select
If dblChildAmount + dblSpouseAmount = dblTaxAmount Then
IncomeTax = 0
Else: IncomeTax = dblTaxAmount - dblChildAmount -
dblSpouseAmount
End If
End If
End Function

In UserForm's OnChange event of ListBox of names of employees:
sngTaxNet = IncomeTax(rngGrossSalary.Offset(intIndex + 1, 0), _
rngChildren.Offset(intIndex + 1, 0), rngSpouse.Offset(intIndex + 1,
0))


Any way to make it work? Any mistakes made writing the code?

Thanks in advance.

Oscar
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Scope of private function in VBA Module

Answered in other post.

--
__________________________________
HTH

Bob

"oscar.c.marin" wrote in message
...
A function declared Private in VBA Module doesn't run on UserForm. Error
reads: Sub or Function not defined.

Function:
Private Function IncomeTax(salaryGross, children, spouse) As Double
Application.ScreenUpdating = False
Call objectVarDeclare

Dim dblChildAmount As Double
Dim dblSpouseAmount As Double
Dim dblTaxAmount As Double
Dim dblTaxNet As Double
Dim rngTaxOne As Single
Set rngTaxOne = salarios_data.Range("tax1")
Dim rngTaxTwo As Single
Set rngTaxTwo = salarios_data.Range("tax2")
Dim rngMinSalary As Range
Set rngMinSalary = salariosData.Range("upper_first")
Dim rngFirstTier As Range
Set rngFirstTier = salarios_data.Range("upper_second")
Dim rngChildCredit As Range
Set rngChildCredit =
salarios_data.Range("child_credit")
Dim rngSpouseCredit As Range
Set rngSpouseCredit = salarios_data.Range("spouse_credit")

dblChildAmount = 0
dblSpouseAmount = 0
dblTaxAmount = 0
If salaryGross <= minSalary Then
dblTaxAmount = 0
IncomeTax = 0
dblChildAmount = 0
dblSpouse_amount = 0
ElseIf salaryGross minSalary And salaryGross <= rngFirstTier Then
dblTaxAmount = ((salaryGross - minSalary) * rngTaxOne.Value)
Select Case children
Case Is 0
dblChildAmount = children * rngChildCredit
Case Is = 0
dblChildAmount = 0
End Select
Select Case spouse
Case Is 0
dblSpouseAmount = spouse * rngSpouseCredit
Case Is = 0
dblSpouseAmount = 0
End Select
If dblChildAmount + dblSpouseAmount = dblTaxAmount
Then
IncomeTax = 0
Else: IncomeTax = dblTaxAmount - dblChildAmount - _
dblSpouseAmount
End If
ElseIf salaryGross rngFirstTier Then
dblTaxAmount = ((rngFirstTier - rngMinSalary) * rngTaxOne.Value) +
_
((salario - rngFirstTier) * rngTaxTwo.Value)
Select Case children
Case Is 0
dblChildAmount = children * rngChildCredit
Case Is = 0
dblChildAmount = 0
End Select
Select Case spouse
Case Is 0
dblSpouseAmount = spouse * rngSpouseCredit
Case Is = 0
dblSpouseAmount = 0
End Select
If dblChildAmount + dblSpouseAmount = dblTaxAmount
Then
IncomeTax = 0
Else: IncomeTax = dblTaxAmount - dblChildAmount -
dblSpouseAmount
End If
End If
End Function

In UserForm's OnChange event of ListBox of names of employees:
sngTaxNet = IncomeTax(rngGrossSalary.Offset(intIndex + 1, 0), _
rngChildren.Offset(intIndex + 1, 0), rngSpouse.Offset(intIndex + 1,
0))


Any way to make it work? Any mistakes made writing the code?

Thanks in advance.

Oscar



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Scope of private function in VBA Module

A function declared as Private is visible only to other procedures
within the same module. It won't be found by code in any other module.
You should declare the procedure as Public or omit the
Private/Public/Friend qualifier altogether. See
http://www.cpearson.com/Excel/Scope.aspx for more information about
the scope of variables and procedures.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Mon, 20 Oct 2008 13:27:11 -0700, oscar.c.marin
wrote:

A function declared Private in VBA Module doesn't run on UserForm. Error
reads: Sub or Function not defined.

Function:
Private Function IncomeTax(salaryGross, children, spouse) As Double
Application.ScreenUpdating = False
Call objectVarDeclare

Dim dblChildAmount As Double
Dim dblSpouseAmount As Double
Dim dblTaxAmount As Double
Dim dblTaxNet As Double
Dim rngTaxOne As Single
Set rngTaxOne = salarios_data.Range("tax1")
Dim rngTaxTwo As Single
Set rngTaxTwo = salarios_data.Range("tax2")
Dim rngMinSalary As Range
Set rngMinSalary = salariosData.Range("upper_first")
Dim rngFirstTier As Range
Set rngFirstTier = salarios_data.Range("upper_second")
Dim rngChildCredit As Range
Set rngChildCredit =
salarios_data.Range("child_credit")
Dim rngSpouseCredit As Range
Set rngSpouseCredit = salarios_data.Range("spouse_credit")

dblChildAmount = 0
dblSpouseAmount = 0
dblTaxAmount = 0
If salaryGross <= minSalary Then
dblTaxAmount = 0
IncomeTax = 0
dblChildAmount = 0
dblSpouse_amount = 0
ElseIf salaryGross minSalary And salaryGross <= rngFirstTier Then
dblTaxAmount = ((salaryGross - minSalary) * rngTaxOne.Value)
Select Case children
Case Is 0
dblChildAmount = children * rngChildCredit
Case Is = 0
dblChildAmount = 0
End Select
Select Case spouse
Case Is 0
dblSpouseAmount = spouse * rngSpouseCredit
Case Is = 0
dblSpouseAmount = 0
End Select
If dblChildAmount + dblSpouseAmount = dblTaxAmount
Then
IncomeTax = 0
Else: IncomeTax = dblTaxAmount - dblChildAmount - _
dblSpouseAmount
End If
ElseIf salaryGross rngFirstTier Then
dblTaxAmount = ((rngFirstTier - rngMinSalary) * rngTaxOne.Value) + _
((salario - rngFirstTier) * rngTaxTwo.Value)
Select Case children
Case Is 0
dblChildAmount = children * rngChildCredit
Case Is = 0
dblChildAmount = 0
End Select
Select Case spouse
Case Is 0
dblSpouseAmount = spouse * rngSpouseCredit
Case Is = 0
dblSpouseAmount = 0
End Select
If dblChildAmount + dblSpouseAmount = dblTaxAmount Then
IncomeTax = 0
Else: IncomeTax = dblTaxAmount - dblChildAmount -
dblSpouseAmount
End If
End If
End Function

In UserForm's OnChange event of ListBox of names of employees:
sngTaxNet = IncomeTax(rngGrossSalary.Offset(intIndex + 1, 0), _
rngChildren.Offset(intIndex + 1, 0), rngSpouse.Offset(intIndex + 1,
0))


Any way to make it work? Any mistakes made writing the code?

Thanks in advance.

Oscar

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
scope of private function called from UserForm fails oscar.c.marin Excel Programming 1 October 20th 08 04:48 AM
Improve method of calling a private function in a private module XP Excel Programming 1 April 30th 08 06:41 PM
private variable: same module, other Sub/Function Stefi Excel Programming 4 July 5th 05 09:10 AM
Call Private Function from ThisWorkbook module Beto[_3_] Excel Programming 3 February 25th 04 01:36 PM
Class Module Scope Trent Argante[_2_] Excel Programming 2 January 6th 04 03:01 PM


All times are GMT +1. The time now is 04:57 PM.

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

About Us

"It's about Microsoft Excel"