aggiungo il codice che ho usato (tutto) ... i dati sono in a1:a120000 ... ho salvato il file (perchè comunque la funzione di Maurizio necessita che il file sia salvato)
così mi restituisce errore impossibile trovare isam installabile ... se lascio la versione 12.0 nella stringa di connessione mi restituisce un errore 80040e37 access non riesce a trovare l'oggetto '1$A1:A120000' ... modificando $ con ! restituisce un errore 80004005 come nel primo caso ma con la descrizione '1!A1:A120000' non è un nome valido ...
ok questo tutto il codice:
Sub test()
Dim d As Double, rng As Excel.Range, res
Set rng = [1!a1:a120000]
d = Timer
res = rNoDup(rng)
rng.Offset(, 1).Resize(UBound(res)).Value = res
Debug.Print "rNoDup tot record: " & UBound(res) & " Tempo: " & Timer - d
d = Timer
res = Unique_With_Pivot(rng)
rng.Offset(, 2).Resize(UBound(res)).Value = res
Debug.Print "Unique_With_Pivot tot record: " & UBound(res) & " Tempo: " & Timer - d
d = Timer
res = GetUnique(rng, 1, True, True)
rng.Offset(, 3).Resize(UBound(res)).Value = res
Debug.Print "GetUnique tot record: " & UBound(res) & " Tempo: " & Timer - d
End Sub
Function rNoDup(rng As Excel.Range, _
Optional rSortOrder As XlSortOrder = xlAscending)
Dim destR As Excel.Range
With Application
.ScreenUpdating = False
.DisplayAlerts = False
Set destR = rng.Parent.Parent.Worksheets.Add.Range(rng.Address)
rng.Copy destR
destR.RemoveDuplicates 1
Set destR = destR.Resize(Application.CountA(destR))
destR.Sort destR, rSortOrder, , , , , , xlGuess
rNoDup = destR.Value
destR.Parent.Delete
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Function
Function Unique_With_Pivot(rng As Excel.Range)
Dim r As Excel.Range, sPFName As String
Dim PC As PivotCache, PT As PivotTable
Set r = rng.Parent.Parent.Worksheets.Add.[a3]
sPFName = rng(1).Value
Set PC = rng.Parent.Parent.PivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:=rng.Address(, , , True))
Set PT = r.Parent.PivotTables.Add(PC, r, "tabella_pivot_x")
With PT.PivotFields(sPFName)
.Orientation = xlRowField
.Position = 1
Unique_With_Pivot = .DataRange.Value
End With
Application.DisplayAlerts = False
r.Parent.Delete
Application.DisplayAlerts = True
End Function
Private Function GetUnique(ByVal RangeObject As Excel.Range _
, ByVal Column As Long _
, ByVal hasHeaders As Boolean _
, ByVal getList As Boolean _
) As Variant
'necessita che la cartella di lavoro sia salvata
'On Error GoTo ErrH
Const cFName = "RCount"
Dim rst As Object 'ADODB.Recordset
Dim c As String
Dim s As String
Dim f As String
With Excel.ThisWorkbook
c = "Provider=Microsoft.ACE.OLEDB.12.0" _
& ";Data Source=" & .FullName _
& ";Extended Properties=""Excel 12.0;ReadOnly=Yes" _
& ";HDR=" & Format$(hasHeaders, ";""Yes"";""No""") & ";""" _
& ";"
End With
With RangeObject
If hasHeaders Then
f = .Cells(1, Column).Value
Else
f = "F" & CStr(Column)
End If
s = "[" _
& .Worksheet.Name & "!" _