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 78 79 80 81 82 83
| Declare Function GetTickCount Lib "kernel32" () As Long
Function IdEmprunteurActuel(plage1 As Range) As String
Dim Cel As Range
IdEmprunteurActuel = ""
Dim index As Integer
index = 0
Dim trouve As Boolean
trouve = False
'Parcourir toute les cellules de la plage
For Each Cel In plage1
If trouve = False Then
If Not Cel.Value = "" Then
index = index + 1
End If
If Cel.Value = "" Then
trouve = True
End If
End If
Next Cel
If trouve = False Then
IdEmprunteurActuel = ""
End If
If trouve = True Then
If Not index = 0 Then
IdEmprunteurActuel = plage1(index, 1)
End If
If index = 0 Then
IdEmprunteurActuel = ""
End If
End If
End Function
Function IdEmprunteurActuelBis(plage1 As Range) As String
Dim Cel As Range, index As Integer, trouve As Boolean, a As Long, b As Long
Dim arrayPlage(), x As Long, y As Long
arrayPlage() = plage1
'Parcourir toute les cellules de la plage
For x = LBound(arrayPlage) To UBound(arrayPlage)
For y = LBound(arrayPlage, 2) To UBound(arrayPlage, 2)
If trouve = False Then
If Not arrayPlage(x, y) = "" Then
a = x: b = y
trouve = True
End If
End If
Next
Next
If trouve = False Then
IdEmprunteurActuelBis = ""
Else
IdEmprunteurActuelBis = arrayPlage(a, b)
End If
End Function
Sub test()
Dim t0 As Long, t1 As Long, t2 As Long, msg As String, x As Long, k As Long, plage As Range
k = 100
Set plage = [Feuil1!A1:G10000]
t0 = GetTickCount()
For x = 1 To k
IdEmprunteurActuel plage
Next
t1 = GetTickCount()
For x = 1 To k
IdEmprunteurActuelBis plage
Next
t2 = GetTickCount()
msg = "Durée de la procédure originale : " + CStr(t1 - t0) + vbCrLf
msg = msg + "Durée de la procédure originale : " + CStr(t2 - t1) + vbCrLf
msg = msg + "la procédure modifiée est donc " + Format((t1 - t0) / (t2 - t1), "0.0") + " fois plus rapide que la procédure originale"
MsgBox msg
End Sub |
Partager