ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   how i can call the function (https://www.excelbanter.com/excel-worksheet-functions/24399-how-i-can-call-function.html)

reneabesmer

how i can call the function
 
Hi .... i have a problem that how i can call a function in Excel VBA the
problem is.

public function price(item)

if(item = "apple") then
price =10
tax=0.2
elseif(item="orange") then
price =8
tax=0.5
end if
end function

But now how to get the exact tax number of apple which is 0.2
thanks in advance






Steve R

I'd recommend against using a function in that way. It means a programmer is
required every time and item is added, a price changes or a tax rate
changes. Why not use a lookup instead?

http://www.techonthenet.com/excel/formulas/lookup.htm
http://www.cpearson.com/excel/lookups.htm

Steve

"reneabesmer" wrote in message
...
Hi .... i have a problem that how i can call a function in Excel VBA the
problem is.

public function price(item)

if(item = "apple") then
price =10
tax=0.2
elseif(item="orange") then
price =8
tax=0.5
end if
end function

But now how to get the exact tax number of apple which is 0.2
thanks in advance








Bob Phillips

set up a table like so in say H1:K20

item price tax
apple 10 0.2
orange 8 .5
etc.

and us

=vlookup(A1,$H$1:$K$20,2,False)*VLOOKUP(A1,$H$1:$K $20,3,False)
--

HTH

RP
(remove nothere from the email address if mailing direct)


"reneabesmer" wrote in message
...
Hi .... i have a problem that how i can call a function in Excel VBA the
problem is.

public function price(item)

if(item = "apple") then
price =10
tax=0.2
elseif(item="orange") then
price =8
tax=0.5
end if
end function

But now how to get the exact tax number of apple which is 0.2
thanks in advance









All times are GMT +1. The time now is 04:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com