vba - Calling Subroutines and values in a User Defined Function (Excel) -



vba - Calling Subroutines and values in a User Defined Function (Excel) -

i grateful if help in simple solution. below have short code user defined function in excel. naming columns (in big spreadsheet) to calculate in sumifs calculation. if want have same columns named , utilize variables writeoff1 , writeoff" in user defined function, how can that? have tried set names of column in subroutine (in same vba project , module) , tried phone call subroutine, looks can not pass names function.

can help solution?

many in advance.

public function writeoff(rev_date variant) variant application.volatile (true) set order_type = sheets("kronos").range("$d:$d") set final_price = sheets("kronos").range("$h:$h") set paidalt = sheets("kronos").range("$i:$i") set excl_rev = sheets("kronos").range("$k:$k") set pamount1 = sheets("kronos").range("$o:$o") set first_pd = sheets("kronos").range("$q:$q") set pmethod1 = sheets("kronos").range("$r:$r") set pamount2 = sheets("kronos").range("$t:$t") set paydate2 = sheets("kronos").range("$v:$v") set pmethod2 = sheets("kronos").range("$w:$w") set pamount3 = sheets("kronos").range("$y:$y") set paydate3 = sheets("kronos").range("$aa:$aa") set pmethod3 = sheets("kronos").range("$ab:$ab") set pamount4 = sheets("kronos").range("$ad:$ad") set paydate4 = sheets("kronos").range("$af:$af") set pmethod4 = sheets("kronos").range("$ag:$ag") set vstatus = sheets("kronos").range("$dl:$dl") set team = sheets("kronos").range("$do:$do") writeoff1 = application.worksheetfunction.sumifs( _ pamount1 _ , team, "<>9" _ , vstatus, "<>rejected", vstatus, "<>unverified" _ , first_pd, rev_date _ , pmethod1, "write off") writeoff2 = application.worksheetfunction.sumifs( _ pamount2 _ , team, "<>9" _ , vstatus, "<>rejected", vstatus, "<>unverified" _ , paydate2, rev_date _ , pmethod2, "write off") writeoff3 = application.worksheetfunction.sumifs( _ pamount3 _ , team, "<>9" _ , vstatus, "<>rejected", vstatus, "<>unverified" _ , paydate3, rev_date _ , pmethod3, "write off") writeoff4 = application.worksheetfunction.sumifs( _ pamount4 _ , team, "<>9" _ , vstatus, "<>rejected", vstatus, "<>unverified" _ , paydate4, rev_date _ , pmethod4, "write off") writeoff = writeoff1 + writeoff2 + writeoff3 + writeoff4 end function

you should create these named ranges, preserve them across functions expose them ranges can work straight on worksheet.

insert named ranges formula ribbon, name manager, new:

in vba, refer them like:

x = application.worksheetfunction.sum(order_type)

on worksheet, can refer them in cell:

=(sum(order_type)) or =vlookup("steve",order_type,2,false), etc.

if prefer not utilize named ranges, set variables public, then, within function, phone call on subroutine assign ranges:

public order_type range public final_price range function myfunction() 'call procedure set public variables setpublicvars 'perform function myfunction = application.worksheetfunction.sum(order_type) end function private sub setpublicvars() set order_type = sheets(1).range("d:d") set final_price = sheets(1).range("h:h") end sub

excel vba user-defined-functions

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -