+ Reply to Thread
Results 1 to 8 of 8

Generate a number between min and max value

  1. #1
    Registered User
    Join Date
    01-07-2010
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    3

    Generate a number between min and max value

    First time poster. Been using Excel for awhile. I am not a savy user by any means, so this may be an easy question.

    Here is what I am needing:

    I have three values for for a row:
    A minimum value
    A maximum value
    An known number

    What I need is a way to insert a command in a cell that will create a number that doesn't exceed the min/max values in each column, but can be multiplied by the known number.

    Example:

    A product has a minimum value of '100' and a maximum value of '500' and an known value of '40'.

    The function would be able to assign a value in a 4th cell - between 2.5 and 12.5 (it doesn't matter which value it returns, as long as it is correct), as those would be the only correct answers. I am unsure if this requires a macro which tries every number until it is greater than the minimum or what.

    I hope I have explained this properly. If you need an Excel spreadsheet with what I need, I can do that (but I don't have it available to produce at this very second).

    Thank you so much for your time.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Generate a number between min and max value

    If you're using XL 2007, and the number does not matter, you could use RANDBETWEEN() where you can specify the minimum and maximum limits for a random number to be generated.

    =RANDBETWEEN(2.5,12.5)

    hth

  3. #3
    Registered User
    Join Date
    01-07-2010
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Generate a number between min and max value

    That would work for that specific problem, however, I have multiple rows with various min, max, and known values.

  4. #4
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Generate a number between min and max value

    Option 1) The value is random between 2.5 and 12.5

    Use =floor(rand()*10+2.5,0.1)

    Option 2) User cannot enter values outside 2.5 and 12.5. Use Validation 'between'
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  5. #5
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Generate a number between min and max value

    I do not see the relation between 40, 100, 500, 2.5 and 12.5

    Show a few examples please.

  6. #6
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Generate a number between min and max value

    I have multiple rows with various min, max, and known values.
    If these values are stored somewhere, you can have the formula refer to them. Say in column A you have the min value, in column B you have the max value. Different in each row. So you can use in row 1


    =RANDBETWEEN(a1,b1)

    and copy this down. The values in columns A and B will be applied for each respective row.

    hth

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,723

    Re: Generate a number between min and max value

    You say you want to generate a random number between 2.5 and 12.5 for your example but you don't say what numbers would be allowed.

    If you have MIN value (100) in A2, MAX value (500) in B2 and "known number" (40) in C2 then you could use either

    =RANDBETWEEN(A2,B2)/C2

    or

    =RAND()*(B2-A2)/C2+A2/C2

    both will give you numbers between 2.5 and 12.5 but the former will only be in increments of 1/C2 (assuming A2 and B2 are always integers), e.g. where C2 is 40, 10.95 or 7.525. While the second can give any number between 2.5 and 12.5, e.g. 10.9999979 [but it will never give you exactly 12.5]

  8. #8
    Registered User
    Join Date
    01-07-2010
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Generate a number between min and max value

    Thanks. The second answer you gave, daddylonglegs, is what I need.

+ 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