Result in 3rd function from existing two functions

S

shabutt

I have two functions A & B in a single module which use "Select Case"
statement and want a third function C in the same module such that

Function C = If(B<=A,B,A)

Please code the function C for me. I am using Excel 2007.

TIA
A novice
 
R

Rick Rothstein

I do not think Excel will allow you to name a function C (or R for that
matter). Assuming your names will be more complex and that you tried to
simplify your problem for us (usually doing that is a bad idea), I'll assume
a function name of CC and, since you didn't tell us anything about the
functions, I used stand-in text surrounded by double angle brackets for the
function's arguments and data type....

Function CC(<<func A arg>>, <<func B arg>>) As <<data type>>
CC = WorksheetFunction.Min(A(<<func A arg>>) , B(<<func B arg>>))
End Function

If the arguments are the same for each function, then the above could be
simplified to this...

Function CC(<<arg>>) As <<data type>>
CC = WorksheetFunction.Min(A(<<arg>>), B(<<arg>>))
End Function
 
S

shabutt

Thank you Sir for your quick response and guidance. Here is my full code:

Function FlatRateTax(TotalIncomePerAnnum)
Select Case TotalIncomePerAnnum
Case Is > 8650000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.2, 0)
Case Is > 4550000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.19, 0)
Case Is > 3550000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.185, 0)
Case Is > 2850000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.175, 0)
Case Is > 2250000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.16, 0)
Case Is > 1950000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.15, 0)
Case Is > 1700000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.14, 0)
Case Is > 1450000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.125, 0)
Case Is > 1200000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.11, 0)
Case Is > 1050000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.1, 0)
Case Is > 900000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.09, 0)
Case Is > 750000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.075, 0)
Case Is > 650000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.06, 0)
Case Is > 550000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.045, 0)
Case Is > 450000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.035, 0)
Case Is > 400000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.025, 0)
Case Is > 350000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.015, 0)
Case Is > 250000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.0075, 0)
Case Is > 180000: FlatRateTax = WorksheetFunction.Round(TotalIncomePerAnnum
* 0.005, 0)
Case Is > 0: FlatRateTax = TotalIncomePerAnnum * 0
End Select
End Function

Function MarginalReliefTax(TotalIncomePerAnnum)
Select Case TotalIncomePerAnnum
Case Is > 8650000: MarginalReliefTax = WorksheetFunction.Round((8650000 *
0.19) + (TotalIncomePerAnnum - 8650000) * 0.6, 0)
Case Is > 4550000: MarginalReliefTax = WorksheetFunction.Round((4550000 *
0.185) + (TotalIncomePerAnnum - 4550000) * 0.6, 0)
Case Is > 3550000: MarginalReliefTax = WorksheetFunction.Round((3550000 *
0.175) + (TotalIncomePerAnnum - 3550000) * 0.5, 0)
Case Is > 2850000: MarginalReliefTax = WorksheetFunction.Round((2850000 *
0.16) + (TotalIncomePerAnnum - 2850000) * 0.5, 0)
Case Is > 2250000: MarginalReliefTax = WorksheetFunction.Round((2250000 *
0.15) + (TotalIncomePerAnnum - 2250000) * 0.5, 0)
Case Is > 1950000: MarginalReliefTax = WorksheetFunction.Round((1950000 *
0.14) + (TotalIncomePerAnnum - 1950000) * 0.4, 0)
Case Is > 1700000: MarginalReliefTax = WorksheetFunction.Round((1700000 *
0.125) + (TotalIncomePerAnnum - 1700000) * 0.4, 0)
Case Is > 1450000: MarginalReliefTax = WorksheetFunction.Round((1450000 *
0.11) + (TotalIncomePerAnnum - 1450000) * 0.4, 0)
Case Is > 1200000: MarginalReliefTax = WorksheetFunction.Round((1200000 *
0.1) + (TotalIncomePerAnnum - 1200000) * 0.4, 0)
Case Is > 1050000: MarginalReliefTax = WorksheetFunction.Round((1050000 *
0.09) + (TotalIncomePerAnnum - 1050000) * 0.4, 0)
Case Is > 900000: MarginalReliefTax = WorksheetFunction.Round((900000 *
0.075) + (TotalIncomePerAnnum - 900000) * 0.3, 0)
Case Is > 750000: MarginalReliefTax = WorksheetFunction.Round((750000 *
0.06) + (TotalIncomePerAnnum - 750000) * 0.3, 0)
Case Is > 650000: MarginalReliefTax = WorksheetFunction.Round((650000 *
0.045) + (TotalIncomePerAnnum - 650000) * 0.3, 0)
Case Is > 550000: MarginalReliefTax = WorksheetFunction.Round((550000 *
0.035) + (TotalIncomePerAnnum - 550000) * 0.3, 0)
Case Is > 500000: MarginalReliefTax = WorksheetFunction.Round((450000 *
0.025) + (TotalIncomePerAnnum - 450000) * 0.3, 0)
Case Is > 450000: MarginalReliefTax = WorksheetFunction.Round((450000 *
0.025) + (TotalIncomePerAnnum - 450000) * 0.2, 0)
Case Is > 400000: MarginalReliefTax = WorksheetFunction.Round((400000 *
0.015) + (TotalIncomePerAnnum - 400000) * 0.2, 0)
Case Is > 350000: MarginalReliefTax = WorksheetFunction.Round((350000 *
0.0075) + (TotalIncomePerAnnum - 350000) * 0.2, 0)
Case Is > 250000: MarginalReliefTax = WorksheetFunction.Round((250000 *
0.005) + (TotalIncomePerAnnum - 250000) * 0.2, 0)
Case Is > 180000: MarginalReliefTax = WorksheetFunction.Round((180000 * 0) +
(TotalIncomePerAnnum - 180000) * 0.2, 0)
Case Is > 0: MarginalReliefTax = TotalIncomePerAnnum * 0
End Select
End Function

Function MontlyTax(TotalIncomePerAnnum) As Integer
MontlyTax = WorksheetFunction.Min(FlatRateTax(TotalIncomePerAnnum),
MarginalReliefTax(TotalIncomePerAnnum))
End Function

This example has been taken from "Excel 2007 Macros Made Easy". Thanks again
for your answer and advice. I will keep in mind.

Regards.
 
P

Patrick Molloy

Function c(TotalIncomePerAnnum)
Dim a As Double
Dim b As Double
a = FlatRateTax(TotalIncomePerAnnum)
b = MarginalReliefTax(TotalIncomePerAnnum)
c = Iff(b <= a, b, a)
End Function
 
S

shabutt

Hi Chuck,

The income levels & tax slabs are particular to my country and the example
mentioned in the book has not been used exactly. The resulting tax is annual.
Sorry to cause trouble and yes we have a highly progressive tax for a third
world country.

I hope this will clear the air.

Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top