Tirage au sort avec pré tirage

gourdin

XLDnaute Impliqué
Bonjour,

J'ai récupéré une macro qui me permet d'attribuer des N° à des noms (cf fichier joint) et qui fonctionne parfaitement (merci les forums).

L'affaire se complique car il arrive que des N° soit attribués à des noms avant le tirage au sort (têtes de série en sport).
Comment attribuer des numéros au sort en tenant compte de numéros déjà attribués ?

Voir pièce jointe

Merci
 

Pièces jointes

  • 00_tirage_sort_forum.xls
    50.5 KB · Affichages: 37

Dranreb

XLDnaute Barbatruc
Avec le module de classe ListeAléat :
VB:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim C&, Plage As Range, LAt As New ListeAléat, T(), L&
If Target(1,1).Value <> "> TIRAGE" Then Exit Sub
C = Target.Column
Set Plage = Cells(8, C + 1).Resize(Cells(60000, C).End(xlUp).Row - 7, 2)
T = Plage.Value
Randomize
LAt.Init UBound(T, 1)
For L = 1 To UBound(T, 1)
   If Not IsEmpty(T(L, 2)) Then LAt.Remettre T(L, 1), L
   Next L
For L = 1 To UBound(T, 1)
   T(L, 1) = LAt.Aléat(L): Next L
Plage.Value = T
End Sub
 
Dernière édition:

gourdin

XLDnaute Impliqué
Avec le module de classe ListeAléat :
VB:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim C&, Plage As Range, LAt As New ListeAléat, T(), L&
If Target(1,1).Value <> "> TIRAGE" Then Exit Sub
C = Target.Column
Set Plage = Cells(8, C + 1).Resize(Cells(60000, C).End(xlUp).Row - 7, 2)
T = Plage.Value
Randomize
LAt.Init UBound(T, 1)
For L = 1 To UBound(T, 1)
   If Not IsEmpty(T(L, 2)) Then LAt.Remettre T(L, 1), L
   Next L
For L = 1 To UBound(T, 1)
   T(L, 1) = LAt.Aléat(L): Next L
Plage.Value = T
End Sub
Celà fonctionne parfaitement merci
 

Statistiques des forums

Discussions
312 198
Messages
2 086 153
Membres
103 135
dernier inscrit
Imagine