Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Result in 3rd function from existing two functions
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Result in 3rd function from existing two functions
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 -- Rick (MVP - Excel) "shabutt" wrote in message ... 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Result in 3rd function from existing two functions
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(TotalIncomePerAn num), 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. "Rick Rothstein" wrote: 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 -- Rick (MVP - Excel) "shabutt" wrote in message ... 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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Result in 3rd function from existing two functions
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 "shabutt" wrote: 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(TotalIncomePerAn num), 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. "Rick Rothstein" wrote: 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 -- Rick (MVP - Excel) "shabutt" wrote in message ... 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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Result in 3rd function from existing two functions
On Wed, 15 Apr 2009 07:25:01 -0700, Patrick Molloy
wrote: 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 "shabutt" wrote: 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) Huge Snip 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) Huge Snip 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(TotalIncomePerAn num), 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. I don't know the author(s) of "Excel 2007 Macros Made Easy", but the functions you show are anything but a <Flat Rate Tax. In fact they are a geometrically progressive tax. If the function 'MonthlyTax()' is correct, then anyone who has a yearly income of more than $1,000,000 a year will owe more taxes than their total income. If 'MonthlyTax should be YearlyTax, it is a whole lot better, but still a highly progressive tax schedule. And there are large discontinuities in the curve of taxes vs income. A flat tax is *flat*. Tax = income * rate. Where rate is a constant. Chuck |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Result in 3rd function from existing two functions
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. "Chuck" wrote: On Wed, 15 Apr 2009 07:25:01 -0700, Patrick Molloy wrote: 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 "shabutt" wrote: 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) Huge Snip 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) Huge Snip 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(TotalIncomePerAn num), 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. I don't know the author(s) of "Excel 2007 Macros Made Easy", but the functions you show are anything but a <Flat Rate Tax. In fact they are a geometrically progressive tax. If the function 'MonthlyTax()' is correct, then anyone who has a yearly income of more than $1,000,000 a year will owe more taxes than their total income. If 'MonthlyTax should be YearlyTax, it is a whole lot better, but still a highly progressive tax schedule. And there are large discontinuities in the curve of taxes vs income. A flat tax is *flat*. Tax = income * rate. Where rate is a constant. Chuck |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Which functions and Procedure to use to have desired result? | Excel Worksheet Functions | |||
[Statistical functions] Function to return result from Z table? | Excel Worksheet Functions | |||
Odd result when copying functions | Excel Worksheet Functions | |||
All arithmetic functions return Zero as result | Setting up and Configuration of Excel | |||
Need to reference existing functions in a custom function: possibl | Excel Worksheet Functions |