+ Reply to Thread
Results 1 to 11 of 11

Sum of random selection from a list (no helper column)

  1. #1
    Registered User
    Join Date
    10-28-2010
    Location
    New York, NY
    MS-Off Ver
    Excel 2007
    Posts
    10

    Exclamation Sum of random selection from a list (no helper column)

    I need a function (or VBA solution) to calculate the sum of a defined number of random selections from a list.

    So essentially function(2,A1:A5) would return the sum of 2 random numbers from A1:A5


    Please help
    Last edited by balper; 12-21-2010 at 07:33 PM.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,445

    Re: Sum of random selection from a list (no helper column)

    Hi,

    How about

    =SUM(INDEX(A1:A5,RANDBETWEEN(1,5)),INDEX(A1:A5,RANDBETWEEN(1,5)))
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    10-28-2010
    Location
    New York, NY
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Sum of random selection from a list (no helper column)

    I need the number of selections to be an input, because I am referencing a different cell for it.

  4. #4
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,445

    Re: Sum of random selection from a list (no helper column)

    Hi,

    You might have some luck with this UDF

    Please Login or Register  to view this content.
    Usage = RandomSum(Number of cells to randomly sum,Range)

    eg, for your initial example

    = RandomSum(2,A1:A5)

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

    Re: Sum of random selection from a list (no helper column)

    and your next requirement? can it be the same number twice?
    "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

  6. #6
    Registered User
    Join Date
    10-28-2010
    Location
    New York, NY
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Sum of random selection from a list (no helper column)

    Works! Thanks so much! [Scratch that, doesn't work]
    Last edited by balper; 12-21-2010 at 01:53 PM.

  7. #7
    Registered User
    Join Date
    10-28-2010
    Location
    New York, NY
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Sum of random selection from a list (no helper column)

    Hi actually this function is not working, I tried some simple tests and it is definitly not returning random selections.

  8. #8
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,445

    Re: Sum of random selection from a list (no helper column)

    The function returns selections that are as random as the rnd function allows (computers can't generate a truly random number). There is much documentation on the web that refers to the methodology that excel uses to generate a random number, and a search of this forum may yield a way to generate a "more random" random number.

  9. #9
    Registered User
    Join Date
    10-28-2010
    Location
    New York, NY
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Sum of random selection from a list (no helper column)

    I actually think there may be an error in the code.

    When I run the function: RANDOMSUM(2,$A$1:$A$10) ten different times for:
    A1=1, A2=2, A3=3... A10=10.

    It returns 3,4,2,4,3,3,3,4,3,3

  10. #10
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,445

    Re: Sum of random selection from a list (no helper column)

    Apologies, you're absolutely correct. Please find amended code below.

    Please Login or Register  to view this content.
    Is it christmas yet?

  11. #11
    Registered User
    Join Date
    10-28-2010
    Location
    New York, NY
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Sum of random selection from a list (no helper column)

    Bingo.

    Hohoho

+ 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