In Excel VBA, how do I write a function that can work in an array formula? -


in excel vba, know can use array formula on multiple cells, selecting range of cells of col c, , doing =a1:10*b1:b10 ctrl-shift-enter.

but suppose instead of multiplication operator, want mymult.

how write mymult function?

function mymult(a integer, b integer)   mymult = * b end function 

what have isn't working

enter image description here

declare arguments variant. use application.caller.hasarray check if udf used array formula:

public function mymult(a, b)   if application.caller.hasarray     dim valsa(), valsb(), r&     valsa = a.value     valsb = b.value      r = lbound(valsa) ubound(valsa)       valsb(r, 1) = valsa(r, 1) * valsb(r, 1)     next      mymult = valsb   else     mymult = * b   end if end function 

note need select c1:c3 before pressing ctrl + shift + enter.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -