Bonjour le fil, thunder23, job75, patricktoulon
•>thunder23
C'est une blague ?
Précédemment , tu m'as demandé comme effacer les noms qui apparaissant automatiquement en utilisant QueryTables...
Sub Macro1_Quatro()
Dim typeCol, Chemin$
Application.ScreenUpdating = False
Chemin = "C:\Users\STAPLE\Documents\bdd.txt"
typeCol = Array(4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & Chemin, Destination:=Cells(Rows.Count, 1).End(3)(2))
.FieldNames = True
.PreserveFormatting = True
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePlatform = 850
.TextFileStartRow = 4
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileTabDelimiter = True
.TextFileColumnDataTypes = typeCol
.TextFileDecimalSeparator = "."
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
.Delete
End With
End Sub
Re
Cela donne quoi avec ces modifs?
NB: Sur la feuille d'import, il faut qu'il y ait déjà les entêtes des colonnes préalablement saisies
Si tu lances plusieurs fois de suite, la macro tu verras que les données se mettent en dessous à chaque fois.VB:Sub Macro1_Quatro() Dim typeCol, Chemin$ Application.ScreenUpdating = False Chemin = "C:\Users\STAPLE\Documents\bdd.txt" typeCol = Array(4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & Chemin, Destination:=Cells(Rows.Count, 1).End(3)(2)) .FieldNames = True .PreserveFormatting = True .RefreshStyle = xlInsertDeleteCells .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePlatform = 850 .TextFileStartRow = 4 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileTabDelimiter = True .TextFileColumnDataTypes = typeCol .TextFileDecimalSeparator = "." .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False .Delete End With End Sub
(et qu'il n'y a toujours pas de noms qui s'ajoutent dans le gestionnaire)
Re
Oui, il suffit de faire le test pour le savoir
Sub test()
Dim tout As String, x, fichier As String
Columns("A:A").NumberFormat = "mm/dd/yyyy"
Cells.ClearContents
fichier = "C:\Users\polux\DeskTop\bdd.txt"
x = FreeFile: Open fichier For Binary Access Read As #x: tout = String(LOF(x), " "): Get #x, , tout: Close #x
With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"): .SetText tout: .PutInClipboard: End With
With ActiveSheet: .Cells(1).Select: .Paste: End With
tbl = Application.Index([A1].CurrentRegion.Value, Evaluate("ROW(" & 1 & ":" & [A1].CurrentRegion.Rows.Count & ")"), Array(1, 3, 6))
Cells.ClearContents
Columns("A:A").NumberFormat = "m/d/yyyy"
Cells(1).Resize(UBound(tbl), UBound(tbl, 2)) = tbl
End Sub
bonjour thunder
je persiste avec mon idée qui comparée a querytable est 4 fois plus rapide avec tes 14000 lignes
j'ai rectifié aussi le problème de date
dans cet exemple si dessous je ne garde que la colonne 1 3 et 6
VB:Sub test() Dim tout As String, x, fichier As String Columns("A:A").NumberFormat = "mm/dd/yyyy" Cells.ClearContents fichier = "C:\Users\polux\DeskTop\bdd.txt" x = FreeFile: Open fichier For Binary Access Read As #x: tout = String(LOF(x), " "): Get #x, , tout: Close #x With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"): .SetText tout: .PutInClipboard: End With With ActiveSheet: .Cells(1).Select: .Paste: End With tbl = Application.Index([A1].CurrentRegion.Value, Evaluate("ROW(" & 1 & ":" & [A1].CurrentRegion.Rows.Count & ")"), Array(1, 3, 6)) Cells.ClearContents Columns("A:A").NumberFormat = "m/d/yyyy" Cells(1).Resize(UBound(tbl), UBound(tbl, 2)) = tbl End Sub
démonstration
Regarde la pièce jointe 1063762
Sub test()
Dim tout As String, x, fichier As String
fichier = "C:\Users\polux\DeskTop\bdd.txt"
x = FreeFile: Open fichier For Binary Access Read As #x: tout = String(LOF(x), " "): Get #x, , tout: Close #x
With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"): .SetText tout: .PutInClipboard: End With
With ActiveSheet.Cells(1, 1)
.CurrentRegion.ClearContents
.EntireColumn.NumberFormat = "mm/dd/yyyy"
.Select
ActiveSheet.Paste
tbl = Application.Index(.CurrentRegion.Value, Evaluate("ROW(" & 1 & ":" & .CurrentRegion.Rows.Count & ")"), Array(1, 2, 3, 8, 9, 11, 17, 18, 19))
.CurrentRegion.ClearContents
.EntireColumn.NumberFormat = "m/d/yyyy"
.Resize(UBound(tbl), UBound(tbl, 2)) = tbl
End With
End Sub
non je n'ai pas regardé je viens de le faire
et bien teste sur ta base de 53000 lignes
sache une chose aussi
c'est que l'array peut être mis dans l'ordre que tu veux
Sub test()
Dim tout As String, x, fichier As String, tbl,x$,colonnes
x = InputBox("tapez les numero de colonnes séparée par une virgule", "liste des colonnes")
If x <> "" Then colonnes = Split(x, ",")
fichier = "C:\Users\polux\DeskTop\bdd.txt"
x = FreeFile: Open fichier For Binary Access Read As #x: tout = String(LOF(x), " "): Get #x, , tout: Close #x
With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"): .SetText tout: .PutInClipboard: End With
With ActiveSheet.Cells(1, 1)
.CurrentRegion.ClearContents
.EntireColumn.NumberFormat = "mm/dd/yyyy"
.Select
ActiveSheet.Paste
tbl = Application.Index(.CurrentRegion.Value, Evaluate("ROW(" & 1 & ":" & .CurrentRegion.Rows.Count & ")"), colonnes)
.CurrentRegion.ClearContents
.EntireColumn.NumberFormat = "m/d/yyyy"
.Resize(UBound(tbl), UBound(tbl, 2)) = tbl
End With
End Sub