Multiple random sections per criteria

Pheonix2332

New Member
Joined
Feb 3, 2021
Messages
20
Office Version
  1. 2013
Platform
  1. Windows
Evening all struggling to sleep as have this on my mind for work,

I have collated the weeks work from a different sheet into a new work book and organised it per member of staff, and now assigned a random number against it , however now I need to have an adjustable number of cases per member of staff to be produced into a separate list

An example being ( on phone so apologies for no screen shots)
Agent 1 has 3 cases out of 15 to be reviewed and the same for agent 2 to agent 30. And would need it to be able to change pending performance of the team so if doing well can be reduced to 2 and if performance drops increase it to 5 - can anybody advise how I could go about this please ?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
i didn't understand it completely, so ...
Map3
ABCDEFGHIJK
1personjobsinspectionperformance now3performancepro rata
2person1292pro rata1500
3person218115
4person3332210
5person4262315
6person5232420
7person6362525
8person7201
9person8332
10person9332
11person10403
12person11312
13person12383
14person13352
15person14171
16person15332
17person16312
18person17242
19person18423
20person19121
21person20201
22person21262
23person22362
24person23413
25person24242
26person25141
27person26151
28person27252
29person28332
30person29393
31person30252
Blad1
Cell Formulas
RangeFormula
B2:B31B2=RANDBETWEEN(10,50)
C2:C31C2=IF($G$2=0,0,ROUND(B2/$G$2,0))
G2G2=VLOOKUP(G1,Tabel1,2,0)
 
Upvote 0
i didn't understand it completely, so ...
sorry was not able to think clearly last night/ early this morning the lay out is like this
1650712594276.png


this is jsut a small sample of cases worked by 2 staff - with a random number generated against each case - I now need to have a way of having this now pull a variable number of cases per member of staff that is the same for all of them - so for 5289505 needs 2 cases and 6023284 needs 2 cases, the names are team managers who then need to run the checks I have on the start page this

1650712778047.png


so when the number of cases to generate changes after Generate it will only show that number max per PID ( staff member)

I have been using the following VBA to get to this point

VBA Code:
 ActiveCell.Select
    ActiveCell.FormulaR1C1 = "=RAND()"
    ActiveCell.Select
    Selection.Copy
    ActiveCell.Range("A1:A61").Select
    Range(Selection, Selection.End(xlDown)).Select
    ActiveSheet.Paste
    ActiveCell.Offset(4, -1).Range("A1").Select
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 1).Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.ClearContents
    ActiveWindow.SmallScroll Down:=-2
    ActiveCell.Offset(-1, 0).Range("A1").Select
    Range(Selection, Selection.End(xlUp)).Select
    ActiveCell.Offset(-1, 0).Range("A1").Select
    Selection.End(xlUp).Select
    ActiveCell.Offset(0, -1).Range("A1").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$F$1148").AutoFilter Field:=5, Criteria1:="<>"
    ActiveSheet.ShowAllData
    Selection.AutoFilter
    ActiveCell.Offset(0, 1).Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Selection.End(xlUp).Select
    ActiveCell.Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    ActiveCell.Offset(1, 0).Range("A1").Select
    Application.CutCopyMode = False
    Selection.AutoFilter
    ActiveWorkbook.Worksheets("data").AutoFilter.Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("data").AutoFilter.Sort.SortFields.Add Key:= _
        ActiveCell.Offset(-1, 0).Range("A1:A1148"), SortOn:=xlSortOnValues, Order:= _
        xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("data").AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    ActiveWorkbook.Worksheets("data").AutoFilter.Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("data").AutoFilter.Sort.SortFields.Add Key:= _
        ActiveCell.Offset(-1, 0).Range("A1:A1148"), SortOn:=xlSortOnValues, Order:= _
        xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("data").AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub

this is a pre recoreded Macro from doing the copy and past to the new sheet and inserting the data needed so will need cleaning up however I need it now to use the random numbers assocated to each Pid in the sheet and then select them based from the cell value on the start sheet.
 
Upvote 0
you're still 2013, because in 2021-365, that can be done by formulas.
Can you add your data with the XL-BB-tool, that is easier to chat.
 
Upvote 0
you're still 2013, because in 2021-365, that can be done by formulas.
Can you add your data with the XL-BB-tool, that is easier to chat.
unfortunately Due to IT restrictions I'm unable to use the XLBB tool, due to where I work they are extremely cautious of external download addons and I have not got the permissions to override it. work in the civil service in the UK
 
Upvote 0
VBA Code:
Sub Pheonix()
     Dim Arr, Res(), MyKeys, MyItems, iNumber
     Set dict = CreateObject("scripting.dictionary")

     With Sheets("Results")
          iNumber = Range("G1").Value     'number of records / staff
          Arr = .Range("A1").CurrentRegion.Value2     'read the range around A1

     'collect all the rownumbers within Arr per staff-member *******************************************************************
          For i = 2 To UBound(Arr)     'loop through the data skipping the headerrow
               skey = Arr(i, 5)     'the staff
               If dict.exists(skey) Then     'exists already
                    dict(skey) = dict(skey) & vbLf & i     'add the row in the array to that key
               Else
                    dict(skey) = i     'add new key with the row within the array
               End If
          Next

     ' make a 2D-array with all the rownumber within Arr, which you random pick, iNumber per staff-member *******************************
          ReDim Res(1 To dict.Count * iNumber, 1 To 1)     'you 'll copy max the number of staffs * the number of records/staff
          MyKeys = dict.keys     'de keys of the dictionary
          MyItems = dict.items     'the items of the dictionary
          For i = 0 To UBound(MyKeys)     'loop through them
               sp = Split(MyItems(i), vbLf)     'split the items = string of all the rownumbers within the array Arr
               For j = 1 To iNumber     'as many records as demanded
                    r = Int(Rnd * (UBound(sp) + 2 - j))     'random pick
                    ptr = ptr + 1     'pointer within the array Res
                    Res(ptr, 1) = sp(r)     'rownumber in array Arr
                    sp(r) = sp(UBound(sp) + 1 - j)     'swap content within sp elements
                    If UBound(sp) - j + 1 <= 0 Then Exit For     'if not enough records for that staffmember, skip to next
               Next
          Next

     ' copy the selected rownumber to your destination   **********************************************************************
          .Range("I2").Resize(ptr, 5).Value = Application.Index(Arr, Res, Array(1, 2, 3, 4, 5))     'copy to I2
     End With
End Sub

Map1
ABCDEFGHIJKLM
1testsdatemanagerstaff10testsdatemanagerstaff
22225/07/222Staff_113713711/07/22137Staff_7
33331/07/223Staff_9696914/06/2269Staff_7
44423/04/224Staff_411711710/05/22117Staff_7
5553/06/225Staff_3797916/07/2279Staff_7
66613/07/226Staff_122822826/05/22228Staff_7
77712/07/227Staff_521121126/04/22211Staff_7
88813/05/228Staff_8474728/04/2247Staff_7
99914/06/229Staff_1018318324/07/22183Staff_7
10101014/05/2210Staff_719319322/07/22193Staff_7
11111120/07/2211Staff_410210216/07/22102Staff_8
12121221/05/2212Staff_10929227/04/2292Staff_8
13131312/05/2213Staff_1151529/04/2215Staff_8
Results
Cell Formulas
RangeFormula
D2:D13,A2:B13A2=ROW()
C2:C251C2=RANDARRAY(250,,TODAY(),TODAY()+100,1)
E2:E251E2="Staff_" & RANDARRAY(250,,1,10,1)
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,215,525
Messages
6,125,325
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top