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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| Option Base 1
Sub essai2()
Dim Pass1 As Double
Dim Pass2 As Double
Dim i As Long
Dim j As Long
Dim Debut As Long
Dim Existe As Boolean
Dim Trouve As Boolean
Dim Plage As Range
Pass1 = Timer
With Sheets("Feuil1")
TabloOri = .Range(.Cells(1, 1), .Cells(.Cells(1, 1).End(xlDown).Row, 3)).Value
End With
With Sheets("Feuil2")
TabloDest = .Range(.Cells(1, 1), .Cells(.Cells(1, 1).End(xlDown).Row, 1)).Value
End With
Debut = 1
For i = LBound(TabloDest, 1) To UBound(TabloDest, 1)
Trouve = False
For j = Debut To UBound(TabloOri, 1)
If Format(CDate(TabloDest(i, 1)), "dd/mm/yyyy hh:mm") = Format(CDate(TabloOri(j, 1)), "dd/mm/yyyy hh:mm") Then
If Not Existe Then
ReDim TabloVal(1)
TabloVal(1) = TabloOri(j, 3)
Existe = True
Else
ReDim Preserve TabloVal(UBound(TabloVal) + 1)
TabloVal(UBound(TabloVal)) = TabloOri(j, 3)
End If
If i < UBound(TabloDest, 1) Then
If Format(CDate(TabloDest(i, 1)), "dd/mm/yyyy hh:mm") <> Format(CDate(TabloDest(i + 1, 1)), "dd/mm/yyyy hh:mm") Then
Debut = j + 1
End If
End If
Trouve = True
Exit For
End If
Next j
If Not Trouve Then
ReDim Preserve TabloVal(UBound(TabloVal) + 1)
TabloVal(UBound(TabloVal)) = "TOTO"
End If
Next i
' application.transpose est limité à 65535 éléments
' donc on construit un tableau temporaire
' qui contient des paquets de 65535 éléments
If UBound(TabloVal) > 65535 Then
' calcul du nombre de tableaux nécessaires
nbtab = UBound(TabloVal) / 65535
If nbtab <> Int(nbtab) Then
nbtab = Int(nbtab) + 1
End If
' pour chaque tableau entier
For i = 1 To nbtab - 1
ReDim TabTemp(1)
TabTemp(1) = TabloVal(1 + (65535 * (i - 1)))
For j = 2 To 65535
ReDim Preserve TabTemp(UBound(TabTemp) + 1)
TabTemp(UBound(TabTemp)) = TabloVal(j + (65535 * (i - 1)))
Next j
With Sheets("Feuil2")
Set Plage = .Range(.Cells(1 + (65535 * (i - 1)), 7), .Cells((65535 * (i - 1)) + UBound(TabTemp), 7))
Plage.Value = Application.WorksheetFunction.Transpose(TabTemp)
End With
Next i
' on gère le dernier tableau à part (il ne contient pas 65535 éléments
ReDim TabTemp(1)
TabTemp(1) = TabloVal(1 + (65535 * (nbtab - 1)))
For j = 2 To (UBound(TabloVal)) - (65535 * (nbtab - 1))
ReDim Preserve TabTemp(UBound(TabTemp) + 1)
TabTemp(UBound(TabTemp)) = TabloVal(j + (65535 * (nbtab - 1)))
Next j
With Sheets("Feuil2")
Set Plage = .Range(.Cells(1 + (65535 * (i - 1)), 7), .Cells((65535 * (i - 1)) + UBound(TabTemp), 7))
Plage.Value = Application.WorksheetFunction.Transpose(TabTemp)
End With
' si le tableau contient moins de 65535, on peut transposer immédiatement
Else
With Sheets("Feuil2")
Set Plage = .Range(.Cells(1, 7), .Cells(UBound(TabloVal), 7))
Plage.Value = Application.WorksheetFunction.Transpose(TabloVal)
End With
End If
Set Plage = Nothing
Pass2 = Timer
MsgBox Pass2 - Pass1 & " secondes "
End Sub |
Partager