Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
scope of private function called from UserForm fails | Excel Programming | |||
Improve method of calling a private function in a private module | Excel Programming | |||
private variable: same module, other Sub/Function | Excel Programming | |||
Call Private Function from ThisWorkbook module | Excel Programming | |||
Class Module Scope | Excel Programming |