Hi All
I have been working on a project that monitors tasks being completed by users. An ask on this is that a people leader can use a button in excel, to generate a new sheet that provides 5 random rows for work competed on any given day, (Users will enter date as confirmation of task completion in column 17 and then their name in column 18.)
I have (with the help of the internet) got as far as the following code.
The above codes simply provides 5 random rows regardless of staff name in column 18. I want to generate data based on name and date. Additionally i won't necessarily want the same volume for each staff member. The desired sample will increase/decrease dependent on quality of work. Therefore, i am thinking adjacent to the button on sheet 1 that will start the macro, i can have a table that a people leader will complete with staff name and number of random rows they want extracted.
Finally, the staff and volume of staff won't be the same everyday, so one day when sample is produced there may only be 1 Staff and on other days there could be 5 staff.
I appreciate this is a chunky big request for support, any feedback and advise will be warmly received.
Thank you in advance.
I have been working on a project that monitors tasks being completed by users. An ask on this is that a people leader can use a button in excel, to generate a new sheet that provides 5 random rows for work competed on any given day, (Users will enter date as confirmation of task completion in column 17 and then their name in column 18.)
I have (with the help of the internet) got as far as the following code.
Code:
Sub dualfilter()
' dualfilter Macro
Dim strInput As String
Sheets("Customer Accounts").Select
strInput = InputBox("Enter date which you require a random sample for. Date to be entered in DD/MM/YYYY format. Where you see prompt to confirm deletion of tab, please hit OK")
Selection.AutoFilter
Sheets("Customer Accounts").Range("A:R").AutoFilter Field:=17, Criteria1:= _
strInput
Cells.Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Select
ActiveSheet.Name = "TempExtract"
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Select
ActiveSheet.Name = "Extractpercentage"
Sheets("TempExtract").Select
Range("A1").Select
ActiveSheet.Paste
Randomize 'Initialize Random number seed
Dim MyRows() As Integer ' Declare dynamic array.
Dim numRows, nxtRow, nxtRnd, chkRnd, copyRow As Integer
'Determine Number of Rows in Customer_Accounts Column A
numRows = Sheets("TempExtract").Range("A" & Rows.Count).End(xlUp).Row
'Allocate 5 elements in Array
ReDim MyRows(5)
'Create 5 Random numbers and fill array
For nxtRow = 1 To 5
getNew:
'Generate Random number
nxtRnd = Int((numRows) * Rnd + 1)
'Check for Header Row number (1)
If nxtRnd = 1 Then GoTo getNew
'Loop through array, checking for Duplicates
For chkRnd = 1 To nxtRow
'Get new number if Duplicate is found
If MyRows(chkRnd) = nxtRnd Then GoTo getNew
Next
'Add element if Random number is unique
MyRows(nxtRow) = nxtRnd
Next
'Loop through Array, copying rows to Sheet5
For copyRow = 1 To 5
Sheets("TempExtract").Rows(MyRows(copyRow)).EntireRow.Copy _
Destination:=Sheets("Extractpercentage").Range("A2")(copyRow, 1)
Next
'Copy header row to newly created extract
Sheets("Customer Accounts").Select
Rows("1:1").Select
Selection.Copy
Sheets("Extractpercentage").Select
Range("1:1").Select
ActiveSheet.Paste
'Delete Temp Extract Sheet as no longer required
Sheets("TempExtract").Select
ActiveWindow.SelectedSheets.Delete
'Rename Exctract percentage with date and time it was created.
Sheets("Extractpercentage").Select
Sheets("Extractpercentage").Name = _
WorksheetFunction.Text(Now(), "m-d-yyyy h_mm_ss am/pm")
'Autofit columns
Cells.Select
Selection.ColumnWidth = 60
Cells.EntireRow.AutoFit
Cells.EntireColumn.AutoFit
End Sub
The above codes simply provides 5 random rows regardless of staff name in column 18. I want to generate data based on name and date. Additionally i won't necessarily want the same volume for each staff member. The desired sample will increase/decrease dependent on quality of work. Therefore, i am thinking adjacent to the button on sheet 1 that will start the macro, i can have a table that a people leader will complete with staff name and number of random rows they want extracted.
Code:
[TABLE="width: 345"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD][/TD]
[TD] A[/TD]
[TD] B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Staff name [/TD]
[TD]desired vol outputs[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Staff1[/TD]
[TD] 4[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Staff2[/TD]
[TD] 4[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Staff3[/TD]
[TD] 6[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Staff4[/TD]
[TD] 6[/TD]
[/TR]
</tbody>[/TABLE]
Finally, the staff and volume of staff won't be the same everyday, so one day when sample is produced there may only be 1 Staff and on other days there could be 5 staff.
I appreciate this is a chunky big request for support, any feedback and advise will be warmly received.
Thank you in advance.