• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Random Allocation

Hi Team,
i got a code for random allocation and made some modification as per my requirement, but the output is not proper.
in D Column need to filter only "9" and in N column there are many users i need to take 10% of user count and need to allocate some person in column P
Example - if user1 has total count of 24 only 2 request has to allocate to "person A to E" if 37 only 4 request has to be allocate, if <10 only 1 request has to allocate, and all the 5 "Person A-E" should be get allocation @ P Column. i enclosed sample file for reference.

Code:
Option Explicit

Sub AllocateUsersBasedOnPercentage()

Dim ws As Worksheet
Dim lastRow As Long
Dim uniqueUsers As Collection
Dim user As Variant
Dim userCounts As Object
Dim personNames As Variant
Dim personIndex As Integer
Dim allocationCount As Integer
Dim i As Long, j As Integer
Dim currentRow As Long
    
    
Set ws = ThisWorkbook.Sheets("Sheet1")
lastRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row
    
' 5 person name to be allocated in P column
personNames = Array("Person A", "Person B", "Person C", "Person C", "Person E")
    
If ws.AutoFilterMode Then ws.AutoFilterMode = False

ws.Range("A1:O" & lastRow).AutoFilter Field:=4, Criteria1:="9"
    
'Collecting unique user in N Column
Set uniqueUsers = New Collection
Set userCounts = CreateObject("Scripting.Dictionary")
On Error Resume Next
For i = 2 To lastRow
If ws.Rows(i).Hidden = False Then
user = ws.Cells(i, "N").Value
If user <> "" Then
If Not userCounts.Exists(user) Then
uniqueUsers.Add user
userCounts.Add user, 0
End If
userCounts(user) = userCounts(user) + 1
End If
End If
Next i
On Error GoTo 0
    
ws.AutoFilterMode = False

'Allocate users based on 10% rule
currentRow = 2
For Each user In uniqueUsers
allocationCount = Application.WorksheetFunction.RoundUp(userCounts(user) * 0.1, 0)
        
' Ensure at least one allocation if count is < 10
If userCounts(user) < 10 Then allocationCount = 1
        
personIndex = 0
For j = 1 To allocationCount
ws.Cells(currentRow, "N").Value = user
ws.Cells(currentRow, "P").Value = personNames(personIndex)
personIndex = (personIndex + 1) Mod 5 ' Rotate through the names
currentRow = currentRow + 1
Next j
Next user

End Sub

Thanks
Jawahar
 

Attachments

  • Allocation.xlsb
    50.9 KB · Views: 7
It's nigh on impossible to code for what you want from code that gives you something you don't want.
Please, attach a workbook with your sheet duplicated, and on the duplicate add the results you want to see. It doesn't have to be for all 555 rows, but at least for the 23 Vignesh Mohandas rows and the 11 Devu Rajeev rows.
 
Hi Sir, Thanks your time,
enclosed the attachment as you required in sheet name "output Required" details updated.
1. in D Column >=9 user in N Column calculated for 10% for example "Vignesh has 23 allocation then 2 person should allocate for him"
2. in D Column <=9 user in N Column calculated for 10% for example "Vignesh has 43 allocation then 4 person should allocate for him"
allocation name given in code like - "Person A", "Person B to E"
if any <=10 only one line should be allocate.

Thanks
Jawahar
 

Attachments

  • Allocation_N.xlsb
    69.2 KB · Views: 4
I've looked very carefully at your file and I can find no logic at all behind the allocation of names in column P on the Outut Required sheet.
Can someone else help me out here?
 
I don't see any logic, either. Don't know where Person A etc. are coming from in the QC column. Baffling.
 
Yes, the same within the initial post code, nothing random but just some static allocation !​
Some cases must be described, elaborated with details in order there is nothing to guess …
 

jawaharprm

Could You try to explain that there should allocate 50 tasks for five person?
Before any code I could offer something.
Check Output Required -sheet Columns AC-AK.
> AC:AD shows number of task per D & N-columns.
> AF shows number of tasks which should allocate.
> AG:AK shows number of task for those five person.
If those match with Your ... then with those could mark allocations to P-column.

Or
Is Your proper output just as You've given?
 

Attachments

  • Allocation_N.xlsb
    85.1 KB · Views: 2
Hi All, Thanks for your time to helping me in the query, i completed with above code with this condition, first i created 2 temp sheet for> 9 and <9 and moved data to both sheet, then i run that macro given above it allocating correctly 10% per person and then i made lookup to main sheet and once completed i deleted that temp sheet.. by this method i getting what i need..
 
Back
Top