+ Reply to Thread
Results 1 to 8 of 8

help for Random no

  1. #1
    Registered User
    Join Date
    05-03-2006
    Posts
    46

    help for Random no

    what i want is:

    1. column B4 - B150 are random nos between 1-16.
    2. column D4 - D15 are random no between 1-16 but dont have No. 2,5,9,11

    any body can help above 2 questions?

    thanx

  2. #2
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    As far as random is concerned, take a look at

    http://www.mcgimpsey.com/excel/udfs/randint.html

    you will random without duplicates, but random between a range with exclusion, I do not think so ...

    HTH
    Carim

  3. #3
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Try this Macro & function - you need both

    Sub FillRandomNumbers()
    Dim rNG As Range
    Dim iNum As Integer
    For Each rNG In Range("b4:b150")
    rNG.Value = RandomNumbersGenerator(1, 16, 0)
    Next rNG
    For Each rNG In Range("d4:d15")
    Do
    iNum = RandomNumbersGenerator(1, 16, 0)
    Select Case iNum
    Case 1, 2 To 4, 6 To 8, 10, 12 To 16
    rNG.Value = iNum
    Exit Do
    End Select
    Loop
    Next rNG
    End Sub


    Public Function RandomNumbersGenerator(Lowest As Long, _
    Highest As Long, Optional Decimals As Integer)
    Application.Volatile 'Remove this line to "freeze" the numbers
    If IsMissing(Decimals) Or Decimals = 0 Then
    Randomize
    RandomNumbersGenerator = Int((Highest + 1 - Lowest) * Rnd + Lowest)
    Else
    Randomize
    RandomNumbersGenerator = Round((Highest - Lowest) * Rnd + Lowest, Decimals)
    End If
    End Function

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi

    Try this custom function :

    Please Login or Register  to view this content.
    Then, when you use the formula =RandyMan() in your worksheet a random number will be generated excluding 2,5,9 and 11.

    HTH

    DominicB

    EDIT : Are we bothered about duplicates here or what ... ?
    Please familiarise yourself with the rules before posting. You can find them here.

  5. #5
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi Mudraker ...

    I like your code very much ...
    Had not experienced this issue before ...

    Cheers
    Carim

  6. #6
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi DominicB,

    Your Function is Ultra **** ...
    I am storing it right away ...

    Cheers
    Carim

  7. #7
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hey Carim

    ****!?!?!?!?!?!?!?!

    Are you a robot, or do you just need to get out more

    DominicB

  8. #8
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Aren't we both in LOVE with XL ... !!!

+ 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