Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Fonction ALEAS

1 réponse
Avatar
Robert
Bonsoir à tous
Sur xl 2003 SP3
La fonction ALEAS me pose des problèmes

soit 2 colonnes de chiffres aléatoires sur 21 lignes : donc des chiffres
aléatoires de 0 à 20 sur mes 2 colonnes : formule matricielle
>>> ça marche si j'appuie sur F9.

Une macro qui réagi à un bouton:
Sub equipes_aleatoires()
Dim maFeuille As String
maFeuille = Application.Sheets(1).Name

Application.Calculation = xlCalculationAutomatic
Worksheets(maFeuille).Calculate
Application.Calculation = xlCalculationManual
End Sub
>>> ça marche aussi.

mais si j'enregistre le classeur à cette étape : la fonction ALEAS est
recalculée ( mais pas à la 2° fois).
Je ne voudrais pas qu'il y ait un recalcul...
Merci de vos réponses
Robert

1 réponse

Avatar
LSteph
Bonsoir,
Tu as déjà analysé l'essentiel du problème.
Faut fixer l'alea dans une macro et laisser des valeurs fixes dans ta
feuille sinon effectivement on est assujeti à chaque recalcul.

Penses à bien mettre randomize au début voir l'aide s ur rnd la fonction
que tu vas pouvoir utiliser.

--
lSteph

Voici un exemple: http://cjoint.com/?ckxnibfS0z

Sub tirage()
Dim lig As Long, col As Byte, i As Byte, j As Long, c As Range

lig = [e2].CurrentRegion.Rows.Count
col = [iv2].End(xlToLeft).Column
Application.ScreenUpdating = False
[a2:b65536].ClearContents
For Each c In [e2].CurrentRegion.Cells
If IsEmpty(c) Then c = "xxxxx"
Next
Randomize
For Each c In Range(Cells(lig + 1, 5), Cells(lig + 1, col))
c = Rnd
Next
Range("e1", Columns(col)).Sort _
Key1:=Range(Cells(lig + 1, 5), Cells(lig + 1, col)), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:úlse, _
Orientation:=xlLeftToRight
Range(Cells(lig + 1, 5), Cells(lig + 1, col)).ClearContents

For i = 5 To col
For Each c In Range(Cells(2, 4), Cells(lig, 4)).Cells
c = Rnd
Next c
Range(Cells(2, 4), Cells(lig, i)).Sort _
Key1:=Range(Cells(2, 4), Cells(lig, 4)), _
Order1:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:úlse, _
Orientation:=xlTopToBottom
Next i
Range(Cells(2, 4), Cells(lig, 4)).ClearContents

For Each c In Range([e2], Cells(lig, col)).Cells
With [a65536].End(xlUp)(2)
.Cells(1) = c
.Offset(0, 1) = Cells(1, c.Column)
End With
Next c
End Sub



Bonsoir à tous
Sur xl 2003 SP3
La fonction ALEAS me pose des problèmes

soit 2 colonnes de chiffres aléatoires sur 21 lignes : donc des chiffres
aléatoires de 0 à 20 sur mes 2 colonnes : formule matricielle
ça marche si j'appuie sur F9.




Une macro qui réagi à un bouton:
Sub equipes_aleatoires()
Dim maFeuille As String
maFeuille = Application.Sheets(1).Name

Application.Calculation = xlCalculationAutomatic
Worksheets(maFeuille).Calculate
Application.Calculation = xlCalculationManual
End Sub
ça marche aussi.




mais si j'enregistre le classeur à cette étape : la fonction ALEAS est
recalculée ( mais pas à la 2° fois).
Je ne voudrais pas qu'il y ait un recalcul...
Merci de vos réponses
Robert