Nombres excel
DDiimtrri
Messages postés
12
Statut
Membre
-
michel_m Messages postés 18903 Date d'inscription Statut Contributeur Dernière intervention -
michel_m Messages postés 18903 Date d'inscription Statut Contributeur Dernière intervention -
bonjour a tous auriez vous une commande sous excel a me faire partager pour génerer une suite de 5000 nombres compris entre 1000 ET 10000 ? ( et que les nombres ne se répète jamais , que l'on retrouve une seul fois le nombre dans les 5000 génerer) .
Merci
Merci
2 réponses
-
bonjour
proposition de macro:
Sub tirer_5K() Dim numeros As Collection Dim cptr As Integer Set numeros = New Collection For cptr = 1 To 5000 tirage = Int(Rnd * 9000) + 1000 On Error Resume Next numeros.Add tirage, CStr(tirage) If Err.Number > 0 Then cptr = cptr - 1 On Error GoTo 0 Next Application.ScreenUpdating = False For cptr = 1 To numeros.Count Cells(cptr, 1) = numeros(cptr) Next End Sub-
plus rapide!
Sub tirer_5K() Dim numeros As Collection Dim tablo Dim cptr As Integer Set numeros = New Collection ReDim tablo(1 To 5000) For cptr = 1 To 5000 tirage = Int(Rnd * 9000) + 1000 On Error Resume Next numeros.Add tirage, CStr(tirage) If Err.Number > 0 Then cptr = cptr - 1 Else tablo(cptr) = tirage End If On Error GoTo 0 Next Application.ScreenUpdating = False Range("A1:A5000") = Application.Transpose(tablo) set numeros=nothing End Sub -
-
-
Oui mais le numero n'est plus numérique de type texte
macro modifiée et complètée ( quelques trucs oubliés tout à l'heure)Sub tirer_5K() Dim numeros As Collection, tirage As String * 9 Dim tablo Dim cptr As Integer Set numeros = New Collection ReDim tablo(1 To 5000) Randomize For cptr = 1 To 5000 '0&ENT((1+ALEA())*100000000) tirage = "0" & Int((1 + Rnd) * 100000000) On Error Resume Next numeros.Add tirage, tirage If Err.Number > 0 Then cptr = cptr - 1 Else tablo(cptr) = tirage End If On Error GoTo 0 Next Application.ScreenUpdating = False Range("A1:A5000") = Application.Transpose(tablo) Set numeros = Nothing End Sub