1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
Option Explicit
Sub Tirage()
Dim Lg& 'Number submitted
Dim i% 'Loop
Dim x& 'Random Row
Dim Tirages% 'Number of draw to set up
Dim Compte As Double 'Count the number of alerts
Dim Samplenb% 'Alerts number in the sameple (defined on 30%)
Dim T 'Timer
T = Time
'ActiveWorkbook.Names.Add Name:="Nom_Nombre_Alerte", RefersTo:="=Alertes!R1C14:R1C16"
'Sheets("Alertes").Range("Nom_Nombre_Alerte").Formula = "=COUNTA(A2:A300000)"
Compte = WorksheetFunction.CountA(Range("A2:A300000")) 'Attribue à la variable "Compte", le nombre de cellule remplies dans la plage "A2:A300000"
'Compte = Range("Nom_Nombre_Alerte").Value
Samplenb = (Compte * 0.3) 'Value to change if other that 30%
Tirages = Samplenb
Sheets(1).Activate
Lg = Range("a" & Rows.Count).End(xlUp).Row - 1
If Tirages > Lg Then Exit Sub 'Control
Application.ScreenUpdating = False
Sheets(1).Activate
'With Sheets("Résultat")
'.Cells.Clear
'.Rows("2:1000000").EntireRow.Delete
'Range("a1:j1").Copy Destination:=.Range("a1")
'End With
'With Sheets("Résultat")
' .Rows("2:100000").EntireRow.Delete
' Range("a2:j2").Copy Destination:=.Range("a2")
'End With
Sheets("Alertes").Copy Before:=Sheets(2)
With Sheets(2) 'Temporary sheet
For i = 1 To Tirages
x = Application.RandBetween(2, Lg)
.Rows(x).Copy Destination:= _
Sheets("Feuille_de_fin").Range("a" & Rows.Count).End(xlUp)(2)
.Rows(x).Delete 'Avoid multiple-occurence
Lg = Lg - 1
Next i
Application.DisplayAlerts = False
.Delete 'Erase temporary sheet
End With
'Call macro_copiecolle
'With Worksheets("Feuille_de_fin")
'.Range("A2:J5000").Copy .Cells(.Rows.Count, "A").End(xlUp)(2)
'ActiveSheet.Range("A2:J5000").Copy .Cells(.Rows.Count, "A").End(xlUp)(2)
'End With |
Partager