Sub test_récup_plage()
Dim fichier$, Tbl
fichier = ThisWorkbook.Path & "\exemple.xlsx" 'à adapter
Tbl = GetcolumnValueOnClosedWbookskeepblank(fichier, "D2:D100000", "Feuil1", False)
Sheets("Feuil1").[A1].Resize(UBound(Tbl), 1) = Tbl
End Sub
Function GetcolumnValueOnClosedWbookskeepblank(fichier As String, RnG As String, Feuille As String, Optional headerTable As Boolean = False)
Dim AdConn As Object, AdoComand As Object, HDR$, RsT As Object, RsTLigne&, RsTCol&, v$, Arr()
Set AdConn = CreateObject("ADODB.Connection")
Set AdoComand = CreateObject("ADODB.Command")
Set RsT = CreateObject("ADODB.RecordSet")
HDR = Array("No", "Yes")(Abs(headerTable))
AdConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & fichier & ";Extended Properties=""Excel 12.0;HDR=NO;IMEX=1"""
AdoComand.ActiveConnection = AdConn
AdoComand.CommandText = "SELECT * from `" & Feuille & "$" & RnG & "`"
RsT.Open AdoComand, , 1, 3
RsT.MoveFirst
Do While Not RsT.EOF
For RsTLigne = 1 To RsT.RecordCount 'lignes
'If Not IsNull(RsT.Fields(0).Value) Then a = a + 1: ReDim Preserve Arr(1 To a): Arr(a) = RsT.Fields(0).Value'( débloquer si on veut sauter les vides)
'ou
a = a + 1: ReDim Preserve Arr(1 To a): Arr(a) = RsT.Fields(0).Value '(bloquer si on veux sauter les vides)
If Not Arr(a) Like "*[A-z,:,€]*" Then
If IsDate(Arr(a)) Then Arr(a) = Format(CDate(Arr(a)), "m/d/yyyy")
Else
Arr(a) = Replace(Arr(a), " €", "€")
End If
RsT.MoveNext
Next
Loop
AdConn.Close: Set RsT = Nothing: Set AdoComand = Nothing: Set AdConn = Nothing
GetcolumnValueOnClosedWbookskeepblank = Application.Transpose(Arr)
End Function