La tabla tiene 1000 filas y está en la hoja TAT. Esta es toda la trama que tengo ahora mismo:
Sub P()
Dim t1 As Single
t1 = Timer()
Percentiles 0,95 '
MsgBox "he finalizado el trabajo" & vbCrLf & "tiempo empleado: " & Timer() - t1
End Sub
Sub Percentiles(P As Double)
Dim H1 As Worksheet
Dim H2 As Worksheet
Dim UF As Long
Dim FilaPrimerDato As Long
Dim FilaUltimoDato As Long
Dim ADatos(10000) As Variant
Dim i As Long
Dim j As Long
Dim k As Long
Set H1 = Worksheets("TAT")
Set H2 = Worksheets("Resumen")
H2.Rows("2:10000").Delete
With H1
UF = .Cells(1000000, 1).End(xlUp).Row
With .Sort.SortFields
.Clear
.Sort.SortFields.Add2 Key:=Range("E2:E" & UF), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add2 Key:=Range("N2:N" & UF), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
End With
With .Sort
.SetRange Range("A1:O" & UF)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
FilaPrimerDato = 2
FilaUltimoDato = UF
k = 0
j = 2
For i = 2 To UF
If .Cells(i + 1, 1) <> .Cells(i, 1) Then
FilaUltimoDato = i + 1
ADatos(k) = .Cells(i, 2)
k = k + 1
H2.Cells(j, 1) = .Cells(FilaPrimerDato, 1)
H2.Cells(j, 2) = WorksheetFunction.Percentile(ADatos, P)
j = j + 1
k = 0
FilaPrimerDato = i + 1
FilaUltimoDato = UF
Else
ADatos(k) = .Cells(i, 2)
k = k + 1
End If
Next
End With
End Sub
Al ejecutar me dice que se ha superado el tiempo de ejecución : error 438 y me marca en amarillo lo que acabo de modificar según lo que me has dicho (lo pongo en negrita)