+ Reply to Thread
Results 1 to 13 of 13

Random Testing by Month

Hybrid View

P Hawk Random Testing by Month 10-03-2015, 12:54 AM
Kaper Re: Random Testing by Month 10-03-2015, 07:38 AM
P Hawk Re: Random Testing by Month 10-05-2015, 02:59 AM
P Hawk Re: Random Testing by Month 10-09-2015, 12:49 AM
Kaper Re: Random Testing by Month 10-09-2015, 01:02 AM
Kaper Re: Random Testing by Month 10-09-2015, 07:54 AM
P Hawk Re: Random Testing by Month 10-10-2015, 12:21 AM
Kaper Re: Random Testing by Month 10-12-2015, 09:54 AM
P Hawk Re: Random Testing by Month 10-16-2015, 01:00 AM
Kaper Re: Random Testing by Month 10-17-2015, 12:19 PM
P Hawk Re: Random Testing by Month 10-25-2015, 12:45 AM
Kaper Re: Random Testing by Month 10-25-2015, 03:22 AM
P Hawk Re: Random Testing by Month 11-30-2015, 12:16 AM
  1. #1
    Registered User
    Join Date
    02-24-2015
    Location
    Florida
    MS-Off Ver
    2010
    Posts
    11

    Random Testing by Month

    I hope someone here can help me solve this problem....I have a group of 160 people which need to be tested each month. Of this group (160), 150 of them have to be tested 4 Times each month (no less or more) and the other 10 people only need to be tested twice (2 times) each month. The daily groups need to be Random, so they will not know what day they might be tested and the amount of each group needs to fluctuate with the number of days in each month. They also cannot have double test in a single week. Would anyone have any ideas on a formula for this, in Non-VBA? Thank you for any help you can give in this matter.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Random Testing by Month

    OK, non-VBA means here that we can fullfill the requirement, but as a month is not 4 weeks long the distribution may not always be "perfectly uniform".

    Let's start from the observation that there is always not more than 5 weeks with working days in a month. (sometimes just 4 but then it will be an easy task to "simplify" the procedures.

    HAve a look in attached sheet in rows 2 and 3 are week starts(mondays) and week ends(fridays) for given month. Columns G:I are "middle weeks containling both Monday and Friday, columns J:K month start/end weeks (may start later than Monday or end earlier than Fri)
    in row 4 is the length of particular week (just deducting start from end and adding 1)
    for 4_tests_a_month_person three dates can be generated as:
    Formula: copy to clipboard
    =G$2+RANDBETWEEN(1,G$4)-1
    (write in G7 and copy to next 2 cells).
    Here generation of random number is integrated with further calculations. Monday date is added random number between 1 and 5 and deduced 1 (we could also generate number between 0 and 4).
    Fourth random number is generated in seprate cell K7 as:
    Formula: copy to clipboard
    =RANDBETWEEN(1,J$4+K$4)
    so for current month it is between 1 and 7, and the generated date is calculated in J7 as:
    Formula: copy to clipboard
    =IF(K7<=J$4,J$2+K7-1,K$2+K7-J$4-1)

    now we can sort the dates in ascending order. in B7:
    Formula: copy to clipboard
    =small($G7:$J7,column(A$1))
    and copy right
    As we used mixed and relative addressing the formulas are ready to copy down 150 rows (I did only 4 more)

    Similar approach as with generation of 4th date can be used to generate dates in 2_times_a_month_person
    so in I15 and J15 we can generate random numbers between 1 and 10 (two first full weeks) and 1 and 12 (all other weeks)
    Formula: copy to clipboard
    =RANDBETWEEN(1,G$4+H$4)
    =RANDBETWEEN(1,I$4+J$4+K$4)

    formula for G15 (refering to I15 is identical as above, and H15 is very similar - we have to check if J15 is smaller than end of first week, second or third.:
    Formula: copy to clipboard
    =IF(J15<=I$4,I$2+J15-1,IF(J15<=I$4+J$4,J$2+J15-I$4-1,K$2+J15-I$4-J$4-1))

    and copy down for another 9 persons (B15 is again small and COLUMN but now we look only into 2 columns).

    Press F9 to recalculate a sheet , copy generated dates and paste them special as values (and date formats) to another shhet. These dates are generated, so will change every time the spredsheet is recalculated.
    Attached Files Attached Files
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    02-24-2015
    Location
    Florida
    MS-Off Ver
    2010
    Posts
    11

    Re: Random Testing by Month

    Thank you for your reply. I wouldn't have thought about going in this direction! I will be working on my sheet, but what I can see this really works! Thank you for your quick reply and expanding my knowledge a little more in Excel. :-)

  4. #4
    Registered User
    Join Date
    02-24-2015
    Location
    Florida
    MS-Off Ver
    2010
    Posts
    11

    Re: Random Testing by Month

    I'm having a problem here...Is there ANY way of Randbetween just giving me a certain number of records for that particular day? In other words, I need approximately 22 people picked out of the list of 150, to have their test on the first Monday, another 22 on Tuesday etc. throughout the month.

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Random Testing by Month

    First lets clarify. Month is not 4 weeks long. Address how it shall be treated. Do we test just each person from First group weekly (so some months 5 times a month)?

  6. #6
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Random Testing by Month

    PS. as you want to test 22 each day out of 150: does it mean that you test also on weekends?

  7. #7
    Registered User
    Join Date
    02-24-2015
    Location
    Florida
    MS-Off Ver
    2010
    Posts
    11

    Re: Random Testing by Month

    Yes, we test on weekends - 7 days a week. 22 People is just a rough estimate of the number needed per day, which will change due to the amount of people each month (160 people *4 test per month =640 total test per month....640 test/31 days per month = 21 people per day). We cannot do 5 test per month on a person - it Must be 4. Is there some way to accomplish this feat using all the days of a month? Thank you for any input you can have in this matter.

  8. #8
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Random Testing by Month

    Note that my solution from post #2 was only for working weekdays (mon-fri). HAs to be ammended to cover whole week. And it is necessary to define the week start - is it Sunday (american style) or Monday (european)?

    VBA would be the best solution.
    It is reasonably easy to fill semi-randomly a range by formula with one condition, but with 2 conditions it is not that easy.

    As I'm trying to understand the "core" of problem - let's have a look 2 weeks back.
    Mr. Brown was tested on September 30th (Wed) - Can he be tested again on Oct 1st (Thu), 5th(Mon), today (12ve-Mon), 31st (Sat)? and then on Nov 2nd (or if you start a week on Sunday - even on Nov 1st?).

  9. #9
    Registered User
    Join Date
    02-24-2015
    Location
    Florida
    MS-Off Ver
    2010
    Posts
    11

    Re: Random Testing by Month

    The week start is Sunday (American style). Yes, Mr. Brown CAN BE tested on September 30th (Wed) AND on Oct 1st (Thu) since it now a new month. Since I'm looking to use ALL the days of the month, even though the 1st of the month may not be a Sunday...I'm leaving in your hands which would be the easiest. Now, about the VBA - I have [I]not[I] worked with it before in Excel, if it is anything like dBaseIII or Oracle programing, I'm sure I can get my endif's in line. I do wish to thank you for your time in this matter.

  10. #10
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Random Testing by Month

    OK, so let's do it in a simple to follow (not the quickest method, but less than a second is probably anyway acceptable.
    Most of the tesks is really done in a worksheet where in columns J ... main procedure works. The key column is M where for a given date from column J a semi-random number is obtained from formula:
    Formula: copy to clipboard
    =IF(COUNTIF($O$1:$O$4,K1)>0,100,0)+L1+RAND()

    (stored in code in R1C1 form):
    Formula: copy to clipboard
    =IF(COUNTIF(R1C15:R4C15,RC[-2])>0,100,0)+RC[-1]+RAND()

    so it is a random number + counter of persons who are already assigned for that day + 100 if the person has already a date from this week (as noted in O1:O4).
    then lowest value is promoted to very top by sorting

    HAve a look how it works in the attachment. To observe it better you can comment-out a line with application.screenupdating and set a breakpoint in a
    next j instruction (take next person) and run the code with either <F5> or "play" button - see the screanshot

    requirements - one of dates for the mionth to be prepared in A1, list of persons in column A (A3 down) , their number of times to be tested in given month in column B.

    The whole code:
    Sub test()
    Dim i As Integer, j As Integer, t As Double, mycalculation As Integer
    Dim month_start As Date, days_in_month As Integer, times_a_month As Integer
    
    'setting stage
    't = Timer
    month_start = Range("A1") - Day(Range("A1")) + 1
    days_in_month = DateSerial(Year(month_start), Month(month_start) + 1, 1) - month_start
    Columns("D:O").ClearContents
    Application.ScreenUpdating = False
    mycalculation = Application.Calculation
    Application.Calculation = xlCalculationManual
    For i = 1 To days_in_month
      Cells(i, "J").Value = month_start + i - 1
      Cells(i, "K").Value = Format(month_start + i - 1, "ww")
      Cells(i, "L").Value = 0
      Cells(i, "M").FormulaR1C1 = "=IF(COUNTIF(R1C15:R4C15,RC[-2])>0,100,0)+RC[-1]+RAND()"
    Next i
    ' main loop - for each person
    For j = 3 To Cells(Rows.Count, "A").End(xlUp).Row
    ' empty used for this person weeks list
      For i = 1 To 4: Cells(i, "O").Value = "": Next i
    ' select rarely used date
      For i = 1 To Cells(j, "B")
    'sort using current values in column M
        Range("M1:M" & days_in_month).Calculate
        Range("J1:M" & days_in_month).Sort key1:=Range("M1"), order1:=xlAscending, Orientation:=xlSortColumns, Header:=xlNo
    ' write it to columns D:G, increase date counter, store used week number
        Cells(j, i + 3) = Range("J1")
        Cells(j, i + 3).NumberFormat = "m/d/yyyy"
        Range("L1") = Range("L1") + 1
        Cells(i, "O") = Range("K1")
      Next i
      Cells(j, 4).Resize(1, 4).Sort key1:=Cells(j, 4), order1:=xlAscending, Header:=xlNo, Orientation:=xlSortRows
    Next j
    Columns("J:O").ClearContents
    'MsgBox Timer - t
    Application.Calculation = mycalculation
    End Sub
    Attached Images Attached Images
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    02-24-2015
    Location
    Florida
    MS-Off Ver
    2010
    Posts
    11

    Re: Random Testing by Month

    Sorry, it's been so long in getting back with you. I've been out sick, I will be working on this when I return to work. Thank you for your help.

  12. #12
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Random Testing by Month

    Good to hear you are better now,

    As for the code - you can just use it as is - the part " To observe it better ... " is intended just to show you how the process goes on. As it works (hopefully) acceptably - you can treat it as a black box and not look inside at the moment :-)

  13. #13
    Registered User
    Join Date
    02-24-2015
    Location
    Florida
    MS-Off Ver
    2010
    Posts
    11

    Re: Random Testing by Month

    Kaper,

    Thank you for your help and patience. I will mark this as Solved and give lots of stars! You are awesome!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Count in Pivot Table by Month - with random dates in data source
    By lindsgray in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 01-08-2015, 04:49 PM
  2. [SOLVED] Auto instert Month names for This month, Last month and Next month
    By hemal89 in forum Word Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2013, 12:01 PM
  3. Replies: 0
    Last Post: 07-18-2013, 04:59 AM
  4. [SOLVED] Testing whether a date falls within a certain month.
    By jngu007 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-09-2012, 06:53 PM
  5. Replies: 3
    Last Post: 09-30-2012, 03:03 PM
  6. Non-random numbers generated by excel's data analysis random gener
    By Allie in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-17-2005, 02:05 AM

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