我有一个项目,我需要随机选择一些案例文件进行审核。我想为执行特定任务的特定员工随机选择案例文件(在A列中标识了雇员,在B列中标识了任务)。
我找到了以下公式,但这并不是我想要的:
=INDEX(A$2:A$100,LARGE(IF(B$2:B$100="Task",ROW(B$2:B$100)-ROW(B$2)+1),INT(RAND()*COUNTIF(B$2:B$100,"Task")+1)))
上述公式仅根据选择的任务从A列返回一个随机名称。我只希望突出显示行以便识别案例文件,所以我想将其构造为条件格式的公式。
答案 0 :(得分:0)
您可以更改oneCellPaintedPer以获得所需的百分比。如果要突出显示五分之一,请放五分之三,三等,以此类推
Sub generateRandoms()
Dim rngOne As Range
Dim rngTwo As Range
Dim rngThree As Range
Dim rngFour As Range
Dim arr() As Variant
Dim counter As Long
Dim rng As Range
Dim cell As Range
Dim oneCellPaintedPer As Long
oneCellPaintedPer = 5
Set rngOne = Range("A1:A25")
Set rngTwo = Range("B1:B25")
Set rngThree = Range("C1:C25")
Set rngFour = Range("D1:D25")
arr = Array(rngOne, rngTwo, rngThree, rngFour)
For counter = 0 To UBound(arr())
Set rng = arr(counter)
For Each cell In rng
If Application.WorksheetFunction.RandBetween(1, oneCellPaintedPer) Mod oneCellPaintedPer = 0 Then
cell.Interior.Color = vbRed
Else
cell.Interior.Color = vbGreen
End If
Next cell
Next counter
End Sub