+ Reply to Thread
Results 1 to 8 of 8

Random number

Hybrid View

vincen1211 Random number 12-22-2008, 05:37 AM
Steel Monkey Random number 12-22-2008, 05:40 AM
arthurbr This link... 12-22-2008, 05:49 AM
davegugg I'd go with =randbetween ,... 12-22-2008, 11:31 AM
shg If you want random,... 12-22-2008, 12:10 PM
vincen1211 @all thanks.. Special to... 12-22-2008, 10:45 PM
shg Would you please mark the... 12-23-2008, 12:57 AM
vincen1211 Done, Thanks !!! 12-23-2008, 10:52 PM
  1. #1
    Registered User
    Join Date
    12-22-2008
    Location
    jakarta
    Posts
    7

    Random number

    I hv 10x10 box (a1..j10) want to fill with random number 1-100
    Any idea how to make function
    Thanks b4
    Last edited by VBA Noob; 12-24-2008 at 06:22 AM.

  2. #2
    Forum Contributor
    Join Date
    11-23-2005
    Location
    Perth, Australia
    Posts
    218

    Random number

    you could try:
    =rand()

    format the cells to suit

  3. #3
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326
    This link should get you started

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884
    I'd go with =randbetween , then you could put in the top and bottom numbers.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    If you want random, non-repeating numbers from 1-100, you can use this function:

    Function RandSeq(Optional bVolatile As Boolean = False) As Long()
        ' shg 2006-0307
        ' Worksheet function *only*
    
        ' Returns a random sequence from 1 to N to the calling range
        ' (entered in a single cell, returns 1)
    
        If bVolatile Then Application.Volatile
    
        Dim nRow    As Long     ' count of rows
        Dim nCol    As Long     ' count of columns
    
        Dim afRnd() As Single   ' random rumbers
        Dim nNum    As Long     ' count of afRnd
        Dim iRnd    As Long     ' index to afRnd
        Dim jRnd    As Long     ' secondary index to afRnd
    
        Dim aiRank() As Long    ' rank array
        Dim iRow    As Long     ' row index to aiRank
        Dim iCol    As Long     ' column index to aiRank
    
        ' verify that the caller is a range
        If Not TypeOf Application.Caller Is Range Then Exit Function
    
        With Application.Caller
            nNum = .Count
            nRow = .Rows.Count
            nCol = .Columns.Count
        End With
    
        ' size arrays to size of range
        ReDim afRnd(0 To nNum - 1)
        ReDim aiRank(0 To nRow - 1, 0 To nCol - 1)
    
        ' get random numbers
        For iRnd = 0 To nNum - 1
            afRnd(iRnd) = Rnd
        Next iRnd
    
        ' rank 'em
        For iRnd = 0 To nNum - 1
            iRow = iRnd \ nCol
            iCol = iRnd Mod nCol
            For jRnd = 0 To nNum - 1
                If afRnd(iRnd) >= afRnd(jRnd) Then aiRank(iRow, iCol) = aiRank(iRow, iCol) + 1
            Next
        Next
        
        RandSeq = aiRank
    End Function
    ... and array-enter this formula in the 10x10 range:

    =RandSeq()
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Registered User
    Join Date
    12-22-2008
    Location
    jakarta
    Posts
    7
    @all thanks..
    Special to arthurbr for link, teach me array-enter and shg for the function..

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Would you please mark the thread as Solved?

    Click the Edit button on your first post in the thread

    Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes

    If more than two days have elapsed since your first post, ask a moderator to mark it.

  8. #8
    Registered User
    Join Date
    12-22-2008
    Location
    jakarta
    Posts
    7
    Done, 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