+ Reply to Thread
Results 1 to 9 of 9

Random Branching

  1. #1
    Registered User
    Join Date
    06-15-2010
    Location
    ATL
    MS-Off Ver
    Excel 2000
    Posts
    34

    Lightbulb Random Branching

    I have 2 cells where I have random numbers that total 100. My problem is that I want to branch each of these cells into 3 more random cells that total the previous cell.

    For example

    A1 = 75: B1=30, C1=22, D1=23


    A2 = 25: B2=11, C2=9, D2=5


    I also don't want any of the 3 cells to be higher than the number 50. I would appreciate any help given, thanks in advance.
    Last edited by 500bloc; 01-28-2012 at 05:03 PM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Random Branching

    Please see the attached.

    I've used a user defined array function. You can see the code in Module1 when you hit Alt F11.
    Attached Files Attached Files
    Martin

  3. #3
    Registered User
    Join Date
    06-15-2010
    Location
    ATL
    MS-Off Ver
    Excel 2000
    Posts
    34

    Re: Random Branching

    Quote Originally Posted by mrice View Post
    Please see the attached.

    I've used a user defined array function. You can see the code in Module1 when you hit Alt F11.

    I thank you for this, but for the strangest reason my computer has problems with Macro. Is their another way this can be done?

  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Random Branching

    Quote Originally Posted by mrice View Post
    Please see the attached.
    I've used a user defined array function. You can see the code in Module1 when you hit Alt F11.
    With your code, any in 3 cells in B, C, D may higher 50.
    I suggest:
    PHP Code: 
    Function ThreeRandomNumbers(MySum) As Variant
    StartAgain
    :
    WorksheetFunction.RandBetween(150)
    WorksheetFunction.RandBetween(150)
    MySum Y
    If 1 Then GoTo StartAgain
    If 50 Then GoTo StartAgain
    ThreeRandomNumbers 
    = Array(XYZ)
    End Function 
    Also A1 and A2 are random too:
    A1=RANDBETWEEN(1,100)
    B1=100-A1
    Last edited by bebo021999; 01-28-2012 at 12:39 PM.
    Quang PT

  5. #5
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Random Branching

    Quote Originally Posted by 500bloc View Post
    I thank you for this, but for the strangest reason my computer has problems with Macro. Is their another way this can be done?
    As my knowdledge, formula can't do. If A1 random 99, B1 random 1, C1 random 2, D1 must be higher than 50 (=99-1-2=96?). With code, excel can start again automatically till getting right result; but with formula, you must press F9 till getting right result.

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Random Branching

    this should do it i think
    Attached Files Attached Files
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  7. #7
    Registered User
    Join Date
    06-15-2010
    Location
    ATL
    MS-Off Ver
    Excel 2000
    Posts
    34

    Re: Random Branching

    Quote Originally Posted by martindwilson View Post
    this should do it i think

    This is exactly what I needed! One question, some cells (b, c or d) are at times higher than 50. Is there a way to change that?

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Random Branching

    not if you want random.so say 75 is split randomly first number is 5 second is 10 the last must =60 you would have to use code even using max() would not fix it as youd get a disproportionate returns of 50

  9. #9
    Registered User
    Join Date
    06-15-2010
    Location
    ATL
    MS-Off Ver
    Excel 2000
    Posts
    34

    Re: Random Branching

    Quote Originally Posted by martindwilson View Post
    not if you want random.so say 75 is split randomly first number is 5 second is 10 the last must =60 you would have to use code even using max() would not fix it as youd get a disproportionate returns of 50

    Alright, thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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