![]() |
|
Forum
|
|
|
#1 (permalink) |
|
Guest
Messages: n/a
|
Bonjour le forum,
Une "t'ite" question toute bête. Voilà, j'ai 10 valeurs numériques dans une plage source( ex A1:E2) Je voudrais pouvoir à la suite d'un clic sur un bouton extraire 5 valeurs au hazard parmis ces 10 valeurs. MERCI!MERCI!MERCI |
| ANNONCES | |||
|
|
|
|
#3 (permalink) |
|
Guest
Messages: n/a
|
Ou en VBA, si tu préfères :
=======================BOF======================== == Option Base 1 Sub Five_Random_Cells() On Error Resume Next ' Ce sont les seules lignes à modifier ! Const coReturn = 5 Dim rg As Range: Set rg = ThisWorkbook.ActiveSheet.Range("A1:E2") ' A partir d'ici on ne touche plus rien... Dim lg() As Double, i As Integer, intNbCells As Integer, st As String intNbCells = rg.Cells.Count For Each Cell In rg i = i + 1 ReDim Preserve lg(i) lg(i) = Cell Next Cell For i = 1 To coReturn st = st & IIf(i = 1, "", vbCr) & i & " : " & lg(Int(Rnd * intNbCells) + 1) Next i MsgBox st, , "Results" End Sub =======================EOF======================== == ++ |
|
|
#4 (permalink) |
|
Guest
Messages: n/a
|
Et puis tant qu'à faire évitons les doublons dans les résultats :
Option Base 1 Sub Five_Random_Cells() On Error Resume Next ' Ce sont les seules lignes à modifier ! Const coReturn = 3 Dim rg As Range: Set rg = ThisWorkbook.ActiveSheet.Range("A1:E2") ' A partir d'ici on ne touche plus rien... Dim db() As Double, i As Integer, intNbCells As Integer, st As String intNbCells = rg.Cells.Count For Each Cell In rg i = i + 1 ReDim Preserve db(i) db(i) = Cell Next Cell i = 0 Dim intTmp As Integer Do intTmp = Int(Rnd * intNbCells) + 1 If db(intTmp) <> Pi Then i = i + 1 st = st & IIf(i = 1, "", vbCr) & i & " : " & db(intTmp) db(intTmp) = Pi End If Loop Until i = coReturn MsgBox st, , "Results" End Sub |
|
|
#5 (permalink) |
|
Guest
Messages: n/a
|
Merci beaucoup,
Encore une petite question , la formule : =INDIRECT(ADDRESS(INT(RAND()*2)+1;INT(RAND()*5)+1) ) me renvoie #ref! et je ne comprends pas pourquoi, peux tu m'éclairer encore un petit peu ? Merci encore |
| ANNONCES | |
| Liens sociaux |
| Outils de la discussion | |
|
|