Function
RandomValue(Database
As
Range)
Dim
rngDatabase
As
Range
Dim
rngRow
As
Range
Dim
iRow
As
Integer
, iArea
As
Integer
For
Each
rngRow
In
Database.Rows
If
Intersect(rngRow, Database.Worksheet.UsedRange)
Is
Nothing
Then
Exit
For
End
If
If
Val(rngRow.Cells(1, 2).Value) = 0
Then
If
rngDatabase
Is
Nothing
Then
Set
rngDatabase = rngRow
Else
Set
rngDatabase = Union(rngDatabase, rngRow)
End
If
End
If
Next
If
Not
rngDatabase
Is
Nothing
Then
iArea = (Rnd(1) * (rngDatabase.Areas.Count - 1)) + 1
iRow = (Rnd(1) * (rngDatabase.Areas(iArea).Rows.Count - 1)) + 1
RandomValue = rngDatabase.Areas(iArea).Cells(iRow, 1)
End
If
End
Function