Cette fonction te fait une recherchev aleatoire, elle marche dans des subs, par contre elle ne marche pas sur le worksheet, je ne comprend pas pourquoi... Quelqu'un saurait-il pourquoi ?
Function recherchevaleatoire(r1 As Range, r2 As Range, i As Integer) As Variant
Dim tablo() As Variant, aleat As Integer
Application.Volatile True
Set x = r2.Find(r1.Value)
If Not x Is Nothing Then
firstAddress = x.Address
Do
ReDim Preserve tablo(j)
tablo(j) = x.Offset(0, CInt(i))
Set x = r2.FindNext(x)
j = j + 1
Loop While Not x Is Nothing And x.Address <> firstAddress
End If
aleat = Application.WorksheetFunction.RandBetween(LBound(tablo), UBound(tablo))
recherchevaleatoire = tablo(aleat)
End Function
Sub toto()
y = recherchevaleatoire(Sheets("Feuil1").Range("A1"), Sheets("Feuil1").Range("A1:B4"), 1)
MsgBox (y)
End Sub
Edit: Yvouille, merci de checker le problème