Is it possible to use excel inbuilt function within user defined or custom made function created by VBA? -
i trying create function in excel via vba , wondering if excel inbuilt function can used within function. example, functions lookup or match.i have solution vba & formula interested know if function can same.
i trying create function vlookup should return value first found item.
'function can return vlookup value 1st found value function slookup(pvalue range, rng range, rng1 range, pindex long) dim cvalue variant dim mvalue long dim uvalue long dim result variant result = "" cvalue = pvalue.value mvalue = application.worksheet.function.match(cvalue, rng, -1) uvalue = pvalue.row if mvalue = uvalue result = application.worksheet.function.vlookup(cvalue, rng1, pindex, 0) else result = 0 end if slookup = result end function
here example uses max() , sum():
public function whatever(rin range) variant dim mx variant mx = application.worksheetfunction.max(rin) whatever = application.worksheetfunction.sum(rin) / mx end function
note not built-in worksheet functions can used in vba. here available ones:
Comments
Post a Comment