Haciendo una pequeñas modificaciones a la macro el resultado es el siguiente con más de 2500 registros el tiempo en un equipo antiguo es de 9 segundos
Option Base 1
Option Explicit
Sub copiar_datos()
Dim datos As Range, datos2 As Range, tabla As Range
Dim f As Integer, c As Integer, cuenta As Integer
Dim i As Integer, j As Integer, inicio As Date
Dim matriz() As Variant, matriz2() As String
Dim funcion As WorksheetFunction
Dim cadena As String, fin As Date, tiempo As Date
inicio = Time
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
ActiveSheet.DisplayPageBreaks = False
Set funcion = WorksheetFunction
Set datos = Range("b3").CurrentRegion
With datos
f = .Rows.Count: c = .Columns.Count
.Columns(c + 3).Offset(-2, 0).Resize(f, 1000).Clear
Set datos2 = .Columns(c + 3).Resize(f, c)
datos.Copy: datos2.PasteSpecial Paste:=xlPasteAllUsingSourceTheme
End With
With datos2
Set datos2 = .Columns(2).Resize(f, c - 1)
End With
ReDim matriz(3): ReDim matriz2(f)
With datos2
For i = 1 To f
For j = 1 To c - 1
matriz(j) = .Cells(i, j)
Next j
matriz2(i) = Join(matriz())
Next i
Range(.Columns(c).Address) = funcion.Transpose(matriz2)
Set datos2 = .CurrentRegion
End With
With datos2
c = .Columns.Count
For i = 1 To f
cadena = .Cells(i, c)
cuenta = funcion.CountIf(.Columns(c), cadena)
matriz2(i) = cuenta
Next i
Range(.Columns(c + 1).Address) = funcion.Transpose(matriz2)
Set datos2 = .CurrentRegion
End With
With datos2
c = .Columns.Count
.Sort _
key1:=Range(.Columns(c).Address), order1:=xlDescending, _
key2:=Range(.Columns(c - 1).Address), order1:=xlAscending
.EntireColumn.AutoFit
Set tabla = .Columns(c + 3).Resize(f, c)
.Copy: tabla.PasteSpecial Paste:=xlPasteAllUsingSourceTheme
.Columns(5).Resize(f, 2).EntireColumn.Delete
.CurrentRegion.EntireColumn.AutoFit
End With
With tabla
.Columns(1).Value = .Columns(c).Value
.RemoveDuplicates Columns:=5
.Columns(5).Resize(f, 2).EntireColumn.Delete
Set tabla = .CurrentRegion
End With
With tabla
.Rows(0) = Array("Coincidencias", "Nº", "Nº", "Nº")
.Rows(0).Font.Bold = True
.Rows(0).Interior.ColorIndex = 44
.Columns(1).Interior.ColorIndex = 4
.Columns(2).Resize(f, 3).Resize(f, 3).Interior.ColorIndex = 37
.EntireColumn.AutoFit
End With
With datos2
.Rows(0) = Array("Orden", "Nº", "Nº", "Nº")
.Rows(0).Font.Bold = True
.Rows(0).Interior.ColorIndex = 44
.Columns(1).Interior.ColorIndex = 4
.Columns(2).Resize(f, 3).Resize(f, 3).Interior.ColorIndex = 37
.EntireColumn.AutoFit
End With
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.CutCopyMode = False
End With
ActiveSheet.DisplayPageBreaks = False
fin = Time
tiempo = fin - inicio
MsgBox (f & " filas procesadas en " & Second(tiempo) & " segundos"), vbInformation, "AVISO"
Set tabla = Nothing: Set datos = Nothing: Set datos2 = Nothing
End Sub