# Randomised Text Values based on Cell Value

#### vishal0589

##### Board Regular
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.

FileChucker

Vishal Srivastava

### Excel Facts

To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

#### vishal0589

##### Board Regular
No replies yet!

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,164,277
Messages
5,836,350
Members
430,421
Latest member
Natas

### 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.

### Which adblocker are you using?

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

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