+ Reply to Thread
Results 1 to 6 of 6

Unique random numbers daily calculation macro

  1. #1
    Registered User
    Join Date
    03-12-2011
    Location
    Palmerston North New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    4

    Unique random numbers daily calculation macro

    Hi there

    I would be extremely grateful if you could help.

    I work in a prison.

    There are 68 cells [1 to 68] in a unit. We have to search 3 random cells a day [this is a minimum requirement].

    The main problem is that I want to generate a macro that selects 3 random cells on a daily basis until all 68 cells are randomly searched at least once a month.


    e.g. On day 1, three of the 68 cells are generated randomly. The three cells to be searched are recorded in day 1.
    On day 2, To keep everyone guessing, an officer will initiate a macro so that another three different cells are generated randomly and recorded in day 2.

    And so on...

    I can readily generate 68 random numbers in one calculation. But, I am utterly stumped on this problem and any help would be appreciated.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Unique random numbers daily calculation macro

    Please Login or Register  to view this content.
    Select three cells, e.g., A1:A3, and paste this into the formula bar:

    =TRANSPOSE(aiRandLong(1,68,3))

    Don't press Enter; instead press and hold the Ctrl and Shift keys, then press Enter.

    If you enter the cell in a horizontal range, e.g., A1:C1, then skip the Transpose:

    =aiRandLong(1,68,3)

    To make the formula update, do Ctrl+Alt+F9.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    03-12-2011
    Location
    Palmerston North New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Unique random numbers daily calculation macro

    Hi there

    Thanks for the post. I've run the macro but duplicates are appearing. I don't think the UDF is disregarding the random cells that have already been listed. Moreover, I think I might need to use VBA code rather than a UDF because of two reasons:

    1. Officers need a simple process [ideally just clicking a command button to activate a macro]

    2. To list the random cells in a table

    e.g.

    A1=Day 1, B1=Cell 1, C1=Cell 2, D1=Cell 3
    A2=Day 2, B1=Cell 4, C1=Cell 5, D1=Cell 6


    Another problem will be on day 23. Because there are 68 unique numbers the macro will need to allow an extra number.

    If you can lend any advice it would again be greatly appreciated. I have attached the excel table format just for clarification on what I am trying to achieve.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    03-12-2011
    Location
    Palmerston North New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Unique random numbers daily calculation macro

    Thanks shg for your perseverance. I understand that I will need to post this in the appropriate forum now that I have shifted the goalposts.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Unique random numbers daily calculation macro

    The UDF works fine, and it does not generate any duplicates for any given formula. It MUST be array entered as I explained.

    If over several days you don't want any duplicates, thats a different problem, and the results each day are not random: Prisoner #1, having his cell searched on day one knows that his cell will not be searched again for 68/3 = 23 days.

  6. #6
    Registered User
    Join Date
    03-12-2011
    Location
    Palmerston North New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Unique random numbers daily calculation macro

    Thanks shg
    You are correct. I have run the macro and there are no duplicates so long as the array is entered correctly. Unfortunately, a lot of our staff who generate the random cell searches are only proficient in basic excel tasks and the UDF procedure will merely confuse them. I will adapt the formula to VBA code and link it to a command button.

    p.s. As well as random cell searches we also conduct reasonable grounds cell searches, search cells that are vacated and periodically conduct search operations of groups of cells. The random three-cell a day searches are minimum compliance requirements to detect contraband and to check cell standards. Security checks are conducted on each cell every day.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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