+ Reply to Thread
Results 1 to 9 of 9

Total Price has to be divided into 30 Random Nos within a range

  1. #1
    Registered User
    Join Date
    08-13-2009
    Location
    London,England
    MS-Off Ver
    Excel 2016
    Posts
    30

    Question Total Price has to be divided into 30 Random Nos within a range

    Hi experts,
    I need your help. Attached the sample file and screenshot


    Lower upper limit will be changed everytime manually-(B2 & C2)
    Price will be changed everytime manually (B4)
    Need 30 random numbers within lower & upper limit.
    TOTAL of those random numbers should be equal to Price (B35 = B4)



    Thanks a lot.

    Regards
    Lavan Joy
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by lavan_joy; 07-06-2017 at 02:25 AM. Reason: upload the new file

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Total Price has to be divided into 30 within a range

    I dont think youve explained this clearly enough, I'm sure you're going to add something to the description that wasn't there in the first place.
    Nevertheless...

    Isn't this simply 45500/30 ?
    Or are you saying the figure 500 and 3000 must be present in that list?
    If the latter then...

    to ensure 500 is in the list
    in F5
    =B2

    to ensure 3000 is in the list
    in F6
    =C2

    then in F7:F34
    =(45500-(B2+C2))/28
    Last edited by Special-K; 07-05-2017 at 04:52 AM.
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Total Price has to be divided into 30 within a range

    Are the numbers to be randomised?

    And in which case the upper limit will need to be restricted and be less than 3000 unless you accept there will be negative numbers.
    Last edited by Richard Buttrey; 07-05-2017 at 05:13 AM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    08-13-2009
    Location
    London,England
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Total Price has to be divided into 30 within a range

    Thanks for your help.Sorry for my bad explanation.

    Lower and upper limit will be changed everytime manually-(B2 & C2)
    Price will be changed everytime manually (B4)
    Need 30 random numbers within lower & upper limit.
    TOTAL of those random numbers should be equal to Price (B35 = B4)

    Edited the post.
    Please check the new excel file.
    Thanks
    Last edited by lavan_joy; 07-05-2017 at 09:20 AM.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Total Price has to be divided into 30 within a range

    I don't see how this is possible without some other rule or rules.

    If you think about it if the numbers are truly random between those limits then the 'average' random number will be
    (45500-30x500) / 30 +500 = 1516.67

    However you're dealing with random numbers and there's no guarantee what the total will be.
    As the problem is stated, in extremis it will be between 30*500 and 30*300, i.e. a total between 15000 & 90000

    More information / limitations are required

  6. #6
    Forum Expert sourabhg98's Avatar
    Join Date
    10-22-2014
    Location
    New Delhi, India
    MS-Off Ver
    Excel 2007, 2013
    Posts
    1,899

    Re: Total Price has to be divided into 30 Random Nos within a range

    This problem is a lot more complex than it seems.

    I am not 100% sure if the distribution of the result generated by this method is Uniform, but I have tried my best.

    Please Login or Register  to view this content.
    Put above code in a standard module.

    Syntax of the Function
    =gen_rand(number of random integers required, lower limit, upper limit, target sum)


    And to use this function just select the range, i.e. B5:B34, then press F2, in the first cell of the selected range now type in the formula "=gen_rand(30,B2,C2,B4)" and then press Ctrl + Enter
    Checked attached for the implemented solution.
    Sample.xlsm

    Hope this helps.
    Happy to Help

    How to upload excel workbooks at this forum - http://www.excelforum.com/the-water-...his-forum.html

    "I don't get things easily, so please be precise and elaborate"

    If someone's post has helped you, thank by clicking on "Add Reputation" below the post.
    If your query is resolved please mark the thread as "Solved" from the "Thread Tools" above.

    Sourabh

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Total Price has to be divided into 30 Random Nos within a range

    Neat. Well done.

    It does raise the rather philosophical question as to whether a number generator system that itself works to a set of rules could be described as a random system.
    Discuss...

  8. #8
    Forum Expert avk's Avatar
    Join Date
    07-12-2007
    Location
    India
    MS-Off Ver
    Microsoft Office 2013
    Posts
    3,223

    Re: Total Price has to be divided into 30 Random Nos within a range

    You required min & max number from list or generation of number list.
    For Min in "B2"
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    In "C2"
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    In "B4" : =B35

    For Generation of number list between 500 to 3000
    In "B5"
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    atul


    If my answer (or that of other members) has helped you, please say "Thanks" by clicking the Add Reputation button at the foot of one of their posts.

    Also: if your problem is solved, please take the time to mark your thread as SOLVED by going to the top of your first post, selecting "Thread Tools" and then "Mark thread as solved".

  9. #9
    Registered User
    Join Date
    08-13-2009
    Location
    London,England
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Total Price has to be divided into 30 Random Nos within a range

    Sourabh! You saved my day. Thanks a lot for the code. My sincere thanks to Richard Buttrey and avk for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 09-12-2015, 04:34 AM
  2. Replies: 19
    Last Post: 10-20-2014, 03:57 PM
  3. Replies: 10
    Last Post: 08-04-2014, 08:18 AM
  4. Total sold price according to stock price list
    By maniootek in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-26-2014, 10:54 PM
  5. [SOLVED] Two COUNTIF Formulas divided by a range to get a percentage
    By Skum in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-19-2013, 10:26 PM
  6. Replies: 1
    Last Post: 07-24-2013, 12:13 PM
  7. unit * price total
    By willy in forum Excel General
    Replies: 2
    Last Post: 03-28-2006, 05:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1