Randomised Text Values based on Cell Value

vishal0589

Board Regular
Joined
May 13, 2014
Messages
63
Hi Friends,
Hope you are doing well.

I need your assistance in this problem.

I want to randomised placement of centain Text values to sepcific rows based on cell value.

Let me clear about my problem.

I have setup a sheet which records attendence of employees.

An employee could takeup a leave,holidays and there will be weeklyoffs too.


I have created a Macro which record attendence based on Leaves (CL/EL), Holidays, and Weekly offs.

Macro:

Private Sub CommandButton1_Click()
Dim a As Range
Dim mx As Integer
Dim tot As Integer
Dim Rw As Long

tot = 0



For Rw = 10 To (Sheet1.[match(2,1/(b10:b4116<>""))] + 9)

For i = 12 To 41
Dim r As Integer
r = Int((41 - 12 + 1) * Rnd() + 12) 'truncate the random number to an integer

Cells(Rw, i).Value = "P" 'set the value in the cell to this random number
Next i

'mx = Cells(Rw, 5).Value Have to check..

For i = 1 To 4

r = Int((41 - 12 + 1) * Rnd() + 12)
tot = tot + r

Cells(Rw, r).Value = "CL" 'set the value in the cell to this random number




Next i

For i = 1 To 3
r = Int((41 * Rnd) + 12) 'truncate the random number to an integer
Cells(Rw, r).Value = "EL" 'set the value in the cell to this random number
Next i




Next Rw

MsgBox "Done!"



End Sub



But my problem is that random placment of leaves,holidays,or wweklyoffs are not based on specific count.


e.g:

If there is month of 30 days and employee have taken 4 Leaves, there is holiday for 2 days and Weekly Offs are about 3 days.

then

Placement is not randomised properly based on leaves,holidays and weeklyoffs in 30 days.


My macro is not based on fixed cell value (I think).

But It gives accurate result in sum of total days i.e. 30 Days.



I have also attached a link of my sample sheet. Please help me out.

FileChucker


Thanks in Advance
Vishal Srivastava
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,214,920
Messages
6,122,272
Members
449,075
Latest member
staticfluids

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