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 65 66 67 68 69 70 71 72 73 74 75 76 77
| Option Explicit
Private Sub Workbook_Open()
'construit les 1er en colonne1
Dim vTst As Long
Dim x As Long
Dim j As Long
Dim d, f, t
Dim vRw As Long
Dim vLLV As Long
Dim vLLR As Long
Dim vbFE As Boolean
Dim vTime1, vTime2
Stop
pbStop = False 'ne pas stopper la macro
vTime1 = Now
'vérifie que la feuille 1er existe, sinon la crée, l'activer dans tous les cas
vbFE = FeuilleExiste("1er")
If vbFE = False Then
Sheets.Add
ActiveSheet.Name = "1er"
Else
Worksheets("1er").Activate
End If
'chargement userform (un label, un bouton stop, une textbox affichant à intervalle régulier le dernier 1er calculé
Load Prm1
Prm1.Show
'ou en était t-on resté dans la construction de la liste ?
vLLR = Cells(Rows.Count, 1).End(xlUp).Row 'dernière ligne
vLLV = Cells(vLLR, 1) 'sa valeur
'Affichage dans textbox
If vLLV = "" Then
Prm1.TextBox1.Text = ""
Else
Prm1.TextBox1.Text = vLLV
End If
'déterminer nombre à tester et dernière ligne d'écriture
If vLLR = 1 Then
Cells(1, 1) = 1
Cells(2, 1) = 2
vTst = 2
vRw = 2
Else
vTst = vLLV
vRw = vLLR
End If
'traitement
Line0:
vRw = vRw + 1 'le prochain premier s'écrira à cette ligne
line1:
vTst = vTst + 1 'nombre à tester
For j = 2 To vRw - 1 'pour chaque premier précédemment testé
If vTst Mod Cells(j, 1) = 0 Then GoTo line1 'ce n'est pas un premier
If vTst / Cells(j, 1) < Cells(j, 1) Then GoTo Line3 'inutile d'aller plus loin, c'est un premier
Next j
Line3:
Cells(vRw, 1) = vTst 'écriture du premier
vTime2 = Now
If vTime2 - vTime1 > 0.0001 Then 'actualisation régulière textbox
Prm1.TextBox1.Text = vTst
vTime1 = Now
End If
If pbStop = True Then 'arréter la macro
Unload Prm1 '
Exit Sub
End If
GoTo Line0
End Sub |
Partager