SOLVED

Numbers calculation

%3CLINGO-SUB%20id%3D%22lingo-sub-968181%22%20slang%3D%22en-US%22%3ENumbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-968181%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3EI'm%20new%20to%20this%20forum%20and%20have%20the%20following%20problem%20to%20solve%3A%20I%20need%20to%20have%20Excel%20automatically%20calculate%20how%20many%20vials%20of%20two%20sizes%20a%20patient%20needs%20to%20get%20dosed.%20The%20vial%20sizes%20are%20500%20and%20350%20mg.%20Example%3A%20Patient%20requires%201780%20mg%2C%20so%20would%20need%203%20x%20500%20mg%20plus%20one%20350%20mg%20vial.%20What%20would%20the%20formula%20look%20like%3F%20-%20Thanks%20in%20advance%20for%20any%20help!%3C%2FP%3E%3CP%3EKind%20regards%3C%2FP%3E%3CP%3EHolgi%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-968181%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ENumbers%20from%20two%20groups%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-968684%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-968684%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F437123%22%20target%3D%22_blank%22%3E%40Holgi%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWith%20the%20help%20of%20below%20Nested%20If%20formulas%20you%20can%20achieve%20your%20requirements%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CU%3E%3CSTRONG%3EFor%20500Mmg%3C%2FSTRONG%3E%20%3C%2FU%3E%3CFONT%20color%3D%22%230000FF%22%3E%3DIF(MOD(B3%2C500)%3D0%2CB3%2F500%2CIF(MOD(B3%2C500)%26gt%3BMOD(B3%2C350)%2CROUNDDOWN((B3%2F500)%2C0)%2C1))%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23000000%22%3E%3CU%3E%3CSTRONG%3EFor%20350mg%3C%2FSTRONG%3E%20%3C%2FU%3E%3CFONT%20color%3D%22%23008000%22%3E(%3DIF(D3*500%26gt%3B%3DB3%2C0%2CIF(MOD(B3%2C350)%3D0%2CB3%2F350%2CIF(MOD(B3%2C500)%26gt%3BMOD(B3%2C350)%2C1%2CROUNDDOWN(B3%2F350%2C0))))%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F152350iDF3CAB270D7D620C%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_0.png%22%20title%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23000000%22%3EA%20sample%20file%20is%20also%20attached%20for%20your%20reference%2C%20hope%20it%20will%20help%20you.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23000000%22%3EIn%20case%20you%20need%20some%20tweak%20in%20the%20formula%20please%20let%20me%20know.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23000000%22%3EThanks%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23000000%22%3ETauqeer%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-968697%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-968697%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F239215%22%20target%3D%22_blank%22%3E%40tauqeeracma%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Tauqeer%2C%3C%2FP%3E%3CP%3EThanks%20so%20much%2C%20thats%20very%20helpful!%20Your%20help%20is%20very%20much%20appreciated!%3C%2FP%3E%3CP%3EHave%20a%20good%20rest%20of%20the%20day!%3C%2FP%3E%3CP%3EKindest%20regards%2C%3C%2FP%3E%3CP%3EHolgi%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-968730%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-968730%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F437123%22%20target%3D%22_blank%22%3E%40Holgi%3C%2FA%3E%26nbsp%3BYou%20are%20welcome%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-968735%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-968735%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F437123%22%20target%3D%22_blank%22%3E%40Holgi%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAre%20you%20seeking%20a%20combination%20of%20500mg%20and%20350mg%20vials%20such%20that%20the%20waste%20is%20minimized%3F%3C%2FP%3E%3CP%3EFor%20example%2C%20say%20the%20prescribed%20amount%20is%20700mg.%20Would%20you%20require%20a%20500mg%20vial%20and%20a%20350mg%20vial%20(150mg%20waste)%20or%20two%20350mg%20vials%20(0mg%20waste).%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-968741%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-968741%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F360420%22%20target%3D%22_blank%22%3E%40PReagan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHello%20PReagan%2C%3C%2FP%3E%3CP%3EYes%2C%20that%20is%20the%20intention%20behind%20the%20use%20of%20two%20different%20vial%20sizes.%20Do%20you%20have%20a%20formula%20which%20would%20consider%20this%3F%20Your%20help%20would%20be%20much%20appreciated!%3C%2FP%3E%3CP%3EKind%20regards%2C%3C%2FP%3E%3CP%3EHolgi%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-970013%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-970013%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F437123%22%20target%3D%22_blank%22%3E%40Holgi%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20with%20most%20problems%20in%20Excel%2C%20there%20are%20many%20solutions%20so%20there%20are%20likely%20many%20solutions%20for%20this%20problem.%20However%2C%20I%20decided%20to%20make%20use%20of%20Excel's%20Solver%20application%20to%20tackle%20your%20issue.%20If%20you%20aren't%20yet%20familiar%20with%20Solver%2C%20refer%20to%20the%20following%20link%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.excel-easy.com%2Fdata-analysis%2Fsolver.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.excel-easy.com%2Fdata-analysis%2Fsolver.html%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAfter%20setting%20up%20your%20problem%2C%20Solver%20can%20determine%20the%20minimum%20waste%20amount%20with%20ease.%20The%20constraints%20I%20used%20for%20your%20problem%20are%20as%20follows%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3ESet%20Objective%3A%20%24B%242%26nbsp%3Bto%20Max%20-%20%3CFONT%20color%3D%22%23333333%22%3E%3CEM%3Ewe%20want%20the%20least%20negative%20value%20for%20waste%3C%2FEM%3E%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3EBy%20Changing%20Variable%20Cells%3A%20%24B%245%3A%24B%246%20-%20%3CFONT%20color%3D%22%23333333%22%3E%3CEM%3Eby%20changing%20the%20vial%20quantities%3C%2FEM%3E%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3E%24B%242%20%26gt%3B%3D%20-349%20-%20%3CFONT%20color%3D%22%23333333%22%3E%3CEM%3Ewe%20want%20the%20waste%20to%20be%20less%20than%20the%20minimum%20vial%20amount%20i.e.%20350mg.%20Waste%20is%20marked%20as%20a%20negative%20amount%20hence%20the%20formula%20being%26nbsp%3B%24B%242%20%26gt%3B%3D%20-349%20and%20not%26nbsp%3B%24B%242%20%26lt%3B%3D%20349.%3C%2FEM%3E%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3E%24B%242%20%26lt%3B%3D%200%20-%20%3CFONT%20color%3D%22%23333333%22%3E%3CEM%3Ethe%20waste%20cannot%20be%20positive%2C%20therefore%20it%20must%20be%20less%20than%20or%20equal%20to%200.%3C%2FEM%3E%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%24B%245%3A%24B%246%20%3D%20integer%20-%20%3CEM%3Ewe%20cannot%20fill%20a%20partial%20vial%2C%20so%20vial%20quantities%20must%20be%20integers.%3C%2FEM%3E%3C%2FP%3E%3CP%3E%24B%247%20%26gt%3B%3D%201%20-%20%3CEM%3Eprescriptions%20must%20contain%20at%20least%201%20vial.%3C%2FEM%3E%3C%2FP%3E%3CP%3E%24C%247%20%26lt%3B%3D%20%24B%241%2B350%20-%20%3CEM%3Ethe%20total%20amount%20of%20mg%20must%20be%20less%20than%20or%20equal%20to%20the%20prescribed%20amount%20plus%20the%20minimum%20vial%20amount%20i.e.%20350mg.%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F152615iCEAE0C7BBBCDC15E%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_1.png%22%20title%3D%22clipboard_image_1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20attached%20an%20example%20file%20for%20your%20use.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3EEdit%3C%2FSTRONG%3E%3A%20I%20apologize%20as%20I%20did%20not%20do%20enough%20testing%20and%20discovered%20an%20error%20in%20my%20initial%20file.%20I%20have%20attached%20the%20updated%20file%20as%20well%20as%20updated%20the%20necessary%20constraints%20in%20my%20reply%20marked%20in%20%3CFONT%20color%3D%22%23FF0000%22%3Ered%3C%2FFONT%3E.%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-971463%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-971463%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F360420%22%20target%3D%22_blank%22%3E%40PReagan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20so%20much%20for%20your%20explanations%2C%20you%20really%20got%20down%20to%20the%20problem%2C%20and%20I%20understand%20the%20Excel%20Solver.%20My%20problem%20is%20now%3A%20how%20to%20translate%20this%20into%20a%20formula%20which%20I%20can%20enter%20into%20an%20Excel%20cell%20and%20then%20have%20it%20automatically%20fill%20out%20the%20value%20once%20the%20set%20objective%20is%20amended%3F%20-%20Thank%20you%20in%20anticipation%20for%20your%20continued%20support!%3C%2FP%3E%3CP%3EKindest%2C%3C%2FP%3E%3CP%3EHolgi%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-975343%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-975343%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F437123%22%20target%3D%22_blank%22%3E%40Holgi%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20a%20formula%20necessary%20or%20would%20a%20VBA%20code%20to%20automatically%20run%20Solver%20suffice%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-977287%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-977287%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F360420%22%20target%3D%22_blank%22%3E%40PReagan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20I%20am%20not%20familiar%20with%20VBA%20codes%2C%20I%20would%20prefer%20a%20formula.%20Thanks%20in%20anticipation%20for%20your%20continued%20support!%3C%2FP%3E%3CP%3EKindest%2C%3C%2FP%3E%3CP%3EHolgi%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-977531%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-977531%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F239215%22%20target%3D%22_blank%22%3E%40tauqeeracma%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Tauqeer%2C%20there%20is%20a%20mistake%20in%20the%20formula%20-%20for%20values%20between%20850%20and%201000%20mg%2C%20the%20formula%20gives%20one%20vial%20each%2C%20which%20is%20not%20sufficient.%20I%20am%20attaching%20the%20file%20which%20you%20had%20sent%20and%20added%20one%20line%20to%20demonstrate%20that%20it%20does%20not%20calculate%20correctly.%20Would%20you%20be%20so%20kind%20and%20have%20a%20look%20into%20it%3F%20-Thanks%20in%20anticipation%2C%20your%20continued%20support%20is%20highly%20appreciated!%3C%2FP%3E%3CP%3EKindest%3C%2FP%3E%3CP%3EHolgi%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-977849%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-977849%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F437123%22%20target%3D%22_blank%22%3E%40Holgi%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESure%20I%20will%20look%20into%20it%20and%20come%20back%20with%20modified%20and%20correct%20formulas.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3ETauqeer%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-977859%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-977859%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F437123%22%20target%3D%22_blank%22%3E%40Holgi%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESince%20you%20indicate%20that%20you%20want%20a%20formula%20that%20automatically%20generates%20the%20most%20efficient%20(i.e.%20least%20waste)%20combination%20of%20vials%2C%20I%20thought%20of%20a%20solution%20that%20I%20would%20like%20to%20share%20with%20you.%20It%20works%20with%20a%20clever%20use%20of%20the%20SUMPRODUCT%20function%20that%20I%20read%20about%20on%20the%20web%20in%20articles%20by%20Mike%20Erickson%20(MrExcel.com)%20and%20Dave%20Burns%20(ExcelJet.net)%3CSPAN%3E%26nbsp%3B.%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3BI%20could%20never%20have%20made%20this%20up%20myself%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EFirst%20I%20created%20a%20matrix%20that%20calculates%20the%20total%20quantity%20of%20all%20possible%20combinations%20of%20ten%20500mg%20vials%20and%20nine%20350mg%20vials.%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3ESecondly%2C%20I%20calculated%20the%20waste%20for%20each%20combination%2C%20based%20on%20the%20dose%20needed%20(%3Dcell%20O32).%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EAll%20you%20need%20to%20do%20is%20enter%20the%20required%20dose%20in%20cell%20%22O32%22.%20The%20most%20efficient%20combination%20of%20vials%20is%20calculated%20in%20Q32%20and%20R32%20by%20the%20SUMPRODUCT%20function.%20Now%2C%20I%20learned%20that%20this%20trick%20only%20works%20if%20the%20array%20that%20this%20function%20evaluates%20contains%20ONLY%20unique%20values.%20I%20started%20off%20with%20a%2010x10%20matrix%20but%20had%20to%20decrease%20to%2010x9%20to%20avoid%20such%20duplicates.%20This%20sets%20the%20maximum%20dose%20to%208150mg%20(10x500%20plus%209x350).%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22inherit%22%3EThe%20attached%20workbook%20displays%20all%20of%20these%20calculations.%20Obviously%2C%20you%20don't%20want%20to%20display%20everything%20all%20the%20time.%20Just%20press%20the%20grouping-buttons%20in%20the%20top%20and%20on%20the%20left%20to%26nbsp%3B%3C%2FFONT%3Ecollapse%3CFONT%20face%3D%22inherit%22%3E%26nbsp%3Bthe%20%22unwanted%22%20columns%20and%20rows.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22inherit%22%3EI%20hope%20you%20find%20this%20useful%20and%20that%20it%20works%20for%20you.%20If%20not%2C%20then%20I%20at%20least%20learned%20something%20myself.%20Thanks!%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-977872%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-977872%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Riny%2C%3C%2FP%3E%3CP%3EThanks%20so%20much%2C%20this%20is%20extremely%20helpful%20for%20me%20-%20the%20waste%20calculation%20is%20very%20important%20and%20it%20seems%20to%20work%20great%20with%20your%20matrix!%3C%2FP%3E%3CP%3EKindest%20regards%2C%3C%2FP%3E%3CP%3EHolgi%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-982553%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-982553%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F437123%22%20target%3D%22_blank%22%3E%40Holgi%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIdeally%2C%20solutions%20suggested%20by%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3Bdeserves%20to%20be%20marked%20as%20'Best%20Response'.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3ETauqeer%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1648645%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1648645%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20was%20really%20helpful%20as%20I%20am%20working%20on%20a%20similar%20project.%20Am%20I%20able%20to%20add%20another%20vial%20size%3F%20Ex%3A%20If%20a%20drug%20come%20in%20500%2C350%2C%20and%20100%20mg%3F%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance!%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1651665%22%20slang%3D%22en-US%22%3ERe%3A%20Numbers%20calculation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1651665%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F787132%22%20target%3D%22_blank%22%3E%40Nedae9%3C%2FA%3E%26nbsp%3BThe%20solution%20that%20I%20provided%20earlier%20only%20works%20for%20two-dimensional%20arrays.%20So%2C%20adding%20a%20third%20dimension%20is%20not%20possible.%20But%2C%20if%20you%20can%20live%20with%20a%20slightly%20more%20manual%20approach%2C%20have%20a%20look%20at%20the%20attached%20workbook.%20Vials%20is%20sizes%20500%2C%20350%20and%20100%20have%20a%20common%20denominator%20of%2050%20(500%3D%3CSTRONG%3E10%3C%2FSTRONG%3Ex50%2C%20350%3D%3CSTRONG%3E7%3C%2FSTRONG%3Ex50%20and%20100%3D%3CSTRONG%3E2%3C%2FSTRONG%3Ex50).%20Let's%20call%20this%20the%20minor%20unit.%20Divide%20the%20required%20dose%20by%2050%20and%20you%20get%20the%20number%20of%20minor%20units%20needed.%20From%20the%20matrix%20in%20the%20attached%20workbook%20it%20can%20then%20be%20fairly%20easily%20determined%20which%20combination%20of%20vials%20is%20needed%2C%20minimising%20waste.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EExample%3A%20Dose%20needed%20%3D%201250%20%3D%2025%20minor%20units%3A%20From%20the%20matrix%20you%20can%20create%20that%20number%20by%2010%20%2B%207%20%2B%208%2C%20thus%201%20x%20500%20%2B%201%20x%20350%20%2B%204%20x%20100.%20Or%2021%20%2B%204%2C%20thus%203%20x%20350%20%2B%202%20x%20100.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENow%2C%20if%20the%20dose%20needed%20is%20%3CSTRONG%3Enot%3C%2FSTRONG%3E%20a%20multiple%20of%2050%20you'll%20end%20up%20with%20some%20waste%2C%20but%20as%20long%20as%20the%20sum%20of%20minor%20units%20used%20is%20nearest%20to%20the%20number%20of%20units%20needed%2C%20the%20waste%20will%20always%20be%20the%20minimum.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20feel%20that%20it%20must%20be%20possible%20to%20put%20all%20of%20this%20in%20a%20mathematical%20model%2Fformula%2C%20but%20that's%20not%20my%20strong%20point.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi all,

I'm new to this forum and have the following problem to solve: I need to have Excel automatically calculate how many vials of two sizes a patient needs to get dosed. The vial sizes are 500 and 350 mg. Example: Patient requires 1780 mg, so would need 3 x 500 mg plus one 350 mg vial. What would the formula look like? - Thanks in advance for any help!

Kind regards

Holgi

16 Replies
Best Response confirmed by Holgi (Occasional Contributor)
Solution

Hi @Holgi 

 

With the help of below Nested If formulas you can achieve your requirements:

 

For 500Mmg =IF(MOD(B3,500)=0,B3/500,IF(MOD(B3,500)>MOD(B3,350),ROUNDDOWN((B3/500),0),1))

For 350mg (=IF(D3*500>=B3,0,IF(MOD(B3,350)=0,B3/350,IF(MOD(B3,500)>MOD(B3,350),1,ROUNDDOWN(B3/350,0))))

 

clipboard_image_0.png

 

A sample file is also attached for your reference, hope it will help you.

 

In case you need some tweak in the formula please let me know.

 

Thanks

Tauqeer

 

@tauqeeracma 

Hi Tauqeer,

Thanks so much, thats very helpful! Your help is very much appreciated!

Have a good rest of the day!

Kindest regards,

Holgi

@Holgi You are welcome

Hello @Holgi,

 

Are you seeking a combination of 500mg and 350mg vials such that the waste is minimized?

For example, say the prescribed amount is 700mg. Would you require a 500mg vial and a 350mg vial (150mg waste) or two 350mg vials (0mg waste).

@PReagan 

Hello PReagan,

Yes, that is the intention behind the use of two different vial sizes. Do you have a formula which would consider this? Your help would be much appreciated!

Kind regards,

Holgi

@Holgi,

 

As with most problems in Excel, there are many solutions so there are likely many solutions for this problem. However, I decided to make use of Excel's Solver application to tackle your issue. If you aren't yet familiar with Solver, refer to the following link:

https://www.excel-easy.com/data-analysis/solver.html

 

After setting up your problem, Solver can determine the minimum waste amount with ease. The constraints I used for your problem are as follows:

 

Set Objective: $B$2 to Max - we want the least negative value for waste

By Changing Variable Cells: $B$5:$B$6 - by changing the vial quantities

$B$2 >= -349 - we want the waste to be less than the minimum vial amount i.e. 350mg. Waste is marked as a negative amount hence the formula being $B$2 >= -349 and not $B$2 <= 349.

$B$2 <= 0 - the waste cannot be positive, therefore it must be less than or equal to 0.

$B$5:$B$6 = integer - we cannot fill a partial vial, so vial quantities must be integers.

$B$7 >= 1 - prescriptions must contain at least 1 vial.

$C$7 <= $B$1+350 - the total amount of mg must be less than or equal to the prescribed amount plus the minimum vial amount i.e. 350mg.

 

clipboard_image_1.png

 

I have attached an example file for your use.

 

Edit: I apologize as I did not do enough testing and discovered an error in my initial file. I have attached the updated file as well as updated the necessary constraints in my reply marked in red.

 

@PReagan 

Thank you so much for your explanations, you really got down to the problem, and I understand the Excel Solver. My problem is now: how to translate this into a formula which I can enter into an Excel cell and then have it automatically fill out the value once the set objective is amended? - Thank you in anticipation for your continued support!

Kindest,

Holgi

@Holgi 

 

Is a formula necessary or would a VBA code to automatically run Solver suffice?

Hi @PReagan 

As I am not familiar with VBA codes, I would prefer a formula. Thanks in anticipation for your continued support!

Kindest,

Holgi

@tauqeeracma 

Hi Tauqeer, there is a mistake in the formula - for values between 850 and 1000 mg, the formula gives one vial each, which is not sufficient. I am attaching the file which you had sent and added one line to demonstrate that it does not calculate correctly. Would you be so kind and have a look into it? -Thanks in anticipation, your continued support is highly appreciated!

Kindest

Holgi

Hi @Holgi 

 

Sure I will look into it and come back with modified and correct formulas.

 

Thanks

Tauqeer

@Holgi 

Since you indicate that you want a formula that automatically generates the most efficient (i.e. least waste) combination of vials, I thought of a solution that I would like to share with you. It works with a clever use of the SUMPRODUCT function that I read about on the web in articles by Mike Erickson (MrExcel.com) and Dave Burns (ExcelJet.net) . I could never have made this up myself

 

First I created a matrix that calculates the total quantity of all possible combinations of ten 500mg vials and nine 350mg vials. Secondly, I calculated the waste for each combination, based on the dose needed (=cell O32). 

 

All you need to do is enter the required dose in cell "O32". The most efficient combination of vials is calculated in Q32 and R32 by the SUMPRODUCT function. Now, I learned that this trick only works if the array that this function evaluates contains ONLY unique values. I started off with a 10x10 matrix but had to decrease to 10x9 to avoid such duplicates. This sets the maximum dose to 8150mg (10x500 plus 9x350).

 

The attached workbook displays all of these calculations. Obviously, you don't want to display everything all the time. Just press the grouping-buttons in the top and on the left to collapse the "unwanted" columns and rows.

 

I hope you find this useful and that it works for you. If not, then I at least learned something myself. Thanks!

@Riny_van_Eekelen 

Hi Riny,

Thanks so much, this is extremely helpful for me - the waste calculation is very important and it seems to work great with your matrix!

Kindest regards,

Holgi

Hi @Holgi 

 

Ideally, solutions suggested by @Riny_van_Eekelen deserves to be marked as 'Best Response'.

 

Thanks

Tauqeer

@Riny_van_Eekelen 

This was really helpful as I am working on a similar project. Am I able to add another vial size? Ex: If a drug come in 500,350, and 100 mg? 

Thanks in advance! 

@Nedae9 The solution that I provided earlier only works for two-dimensional arrays. So, adding a third dimension is not possible. But, if you can live with a slightly more manual approach, have a look at the attached workbook. Vials is sizes 500, 350 and 100 have a common denominator of 50 (500=10x50, 350=7x50 and 100=2x50). Let's call this the minor unit. Divide the required dose by 50 and you get the number of minor units needed. From the matrix in the attached workbook it can then be fairly easily determined which combination of vials is needed, minimising waste.

 

Example: Dose needed = 1250 = 25 minor units: From the matrix you can create that number by 10 + 7 + 8, thus 1 x 500 + 1 x 350 + 4 x 100. Or 21 + 4, thus 3 x 350 + 2 x 100.

 

Now, if the dose needed is not a multiple of 50 you'll end up with some waste, but as long as the sum of minor units used is nearest to the number of units needed, the waste will always be the minimum.

 

I feel that it must be possible to put all of this in a mathematical model/formula, but that's not my strong point.