SOLVED

Excel- Split a number

%3CLINGO-SUB%20id%3D%22lingo-sub-1632623%22%20slang%3D%22en-US%22%3EExcel-%20Split%20a%20number%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1632623%22%20slang%3D%22en-US%22%3E%3CP%3EDear%20Sir%2C%3C%2FP%3E%3CP%3EI%20am%20facing%20problem%20in%20excel%20for%20splitting%20a%20number%20into%20different%20random%20parts%3C%2FP%3E%3CP%3ELike%3C%2FP%3E%3CP%3EI%20want%20to%20split%2045%20into%207%20random%20parts%3C%2FP%3E%3CP%3E%221st%20part%20between%200-12%22%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%22%202nd%20part%20between%200-12%22%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%22%203rd%20part%20between%200-12%22%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%22%204th%20part%20between%200-6%22%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%22%205th%20part%20between%200-6%22%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%22%206th%20part%20between%200-6%22%3C%2FP%3E%3CP%3E%22%207th%20part%20between%200-6%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EAll%20numbers%20should%20be%20randomly%20selected%20and%20the%20sum%20of%20all%207%20parts%20must%20be%2045.%20Likewise%2C%20I%20have%20several%20numbers%20to%20divide%20like%2045%2C55%2C32%2C33%2C%20etc%20but%20the%20split%20will%20be%20in%207%20parts%20as%20mentioned.%3C%2FP%3E%3CP%3EPlease%20help%20me%2C%20if%20you%20can%20help%20me%20in%20the%20splitting%20of%20one%20number%20I%20will%20do%20the%20rest.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3EDr.%20Ashish%20Sharma%3C%2FP%3E%3CP%3EAssistant%20Professor%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1632623%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1632802%22%20slang%3D%22en-US%22%3ERe%3A%20Excel-%20Split%20a%20number%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1632802%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F781271%22%20target%3D%22_blank%22%3E%40ashunjoy_1911%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDear%20Dr.%20Sharma%3C%2FP%3E%3CP%3EPlease%20find%20a%20file%20that%20has%20a%20VBA%20script.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Einput%20your%20number%20in%20cell%20A1%20(for%20example%2045)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethe%20function%20will%20use%20randbetween...%20until%20the%20sum%20will%20be%2045%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eif%20you%20want%2055%2C%20just%20change%20the%20value%20in%20cell%20A1%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ebest%20regards%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1632844%22%20slang%3D%22en-US%22%3ERe%3A%20Excel-%20Split%20a%20number%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1632844%22%20slang%3D%22en-US%22%3EIs%20this%20something%20you%20will%20only%20need%20to%20do%20once%20for%20a%20few%20numbers%2C%20or%20will%20you%20need%20to%20do%20this%20repeatedly%3F%3CBR%20%2F%3E%3CBR%20%2F%3EI%20would%20probably%20generate%20all%20of%20the%20number%20combinations%2C%20then%20see%20how%20many%20sum%20to%20the%20target%20value%2C%20and%20then%20get%20a%20random%20number%20between%201%20and%20the%20number%20of%20combinations%20equaling%20the%20target%20value%20to%20randomly%20pick%20one%20of%20them.%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20you%20need%20to%20do%20this%20repeatedly%2C%20I%20would%20probably%20generate%20all%20of%20the%20number%20combinations%20and%20save%20them%20in%20a%20table%20with%20a%20total%20column%20(which%20I%20don't%20think%20will%20fit%20in%20a%20worksheet%2C%20may%20need%20to%20put%20it%20in%20a%20text%2Fcsv%20file%20and%20read%20it%20in).%20That%20way%2C%20you%20wouldn't%20have%20to%20generate%20all%20of%20the%20number%20combinations%20every%20time%20you%20needed%20to%20do%20this%20and%20save%20quite%20a%20bit%20of%20time.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1632846%22%20slang%3D%22en-US%22%3ERe%3A%20Excel-%20Split%20a%20number%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1632846%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F746148%22%20target%3D%22_blank%22%3E%40Ramiz_Assaf%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPerfect%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20very%20much%2C%20Sir.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1633008%22%20slang%3D%22en-US%22%3ERe%3A%20Excel-%20Split%20a%20number%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1633008%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F746148%22%20target%3D%22_blank%22%3E%40Ramiz_Assaf%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESir%2C%20I%20got%20stuck%20in%20my%20original%20file.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20you%20give%20a%20generous%20solution%20for%20the%20attached%20file%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Dear Sir,

I am facing problem in excel for splitting a number into different random parts

Like

I want to split 45 into 7 random parts

"1st part between 0-12"  

" 2nd part between 0-12"  

" 3rd part between 0-12"  

" 4th part between 0-6"  

" 5th part between 0-6"  

" 6th part between 0-6"

" 7th part between 0-6"    

All numbers should be randomly selected and the sum of all 7 parts must be 45. Likewise, I have several numbers to divide like 45,55,32,33, etc but the split will be in 7 parts as mentioned.

Please help me, if you can help me in the splitting of one number I will do the rest.

 

Thanks

Dr. Ashish Sharma

Assistant Professor

9 Replies
Highlighted
Best Response confirmed by ashunjoy_1911 (Occasional Contributor)
Solution

@ashunjoy_1911 

 

Dear Dr. Sharma

Please find a file that has a VBA script.

 

input your number in cell A1 (for example 45)

 

the function will use randbetween... until the sum will be 45

 

if you want 55, just change the value in cell A1

 

best regards

 

Highlighted

Hello @ashunjoy_1911,

 

I'm not sure that I fully understand your problem. It could be possible that not all 7 parts are random. For example, say random numbers of the first 5 parts were 12, 10, 12, 5, 6. The sum would already be 45 and thus the final 2 parts must be 0. This would make the final two parts non-random as they are dependent on the sum of the previous parts.

Highlighted
Is this something you will only need to do once for a few numbers, or will you need to do this repeatedly?

I would probably generate all of the number combinations, then see how many sum to the target value, and then get a random number between 1 and the number of combinations equaling the target value to randomly pick one of them.

If you need to do this repeatedly, I would probably generate all of the number combinations and save them in a table with a total column (which I don't think will fit in a worksheet, may need to put it in a text/csv file and read it in). That way, you wouldn't have to generate all of the number combinations every time you needed to do this and save quite a bit of time.
Highlighted

@Ramiz_Assaf 

 

Perfect  

 

Thank you very much, Sir.

Highlighted

@Ramiz_Assaf 

 

Sir, I got stuck in my original file.

 

Can you give a generous solution for the attached file? 

 

 

Highlighted

@ashunjoy_1911 

 

Press F9 to generate solutions

accepted solutions will become green

keep pressing F9 until all the column becomes green

 

hope this solution work, I dunno what to do with fractions (round up or down)

Highlighted

@Ramiz_Assaf 

 

Thank you Assaf

 

Actually the excel shows me error in the formula as I am using Office 2016

In 2016 "IFS" function is not working. "IFS" function is introduced after 2016.

 

Error- =_xlfn.IFS($B$1=0,0,$I16<>$A16,RANDBETWEEN(B$3,B$4),TRUE,B16)

 

Can you provide nested IF, Please

Highlighted

@ashunjoy_1911 

 

Please find a modified version attached

I had fun doing this project

 

 

Highlighted

@Ramiz_Assaf 

 

I am really grateful that you have taken up this task.

 

You really become an escape boat for me.

 

Regards

Dr. Ashish