Re
•>thunder23
J'ai lu le message#51
1) je n'aime pas les questions à tiroir
2) Mon code fonctionne pour ce qui était demandé au départ
3) Et la réponse à la question du#51 est évidente
J'importe tout puis je créé une macro qui supprime les colonnes non désirées et ce après l'import
Sub test3()
fichier = Application.GetOpenFilename("Text Files (*.txt), *.txt", 1, "ouvrir un fichier")
If fichier = "" Then Exit Sub
x = InputBox("tapez les numero de colonnes séparée par une virgule", "liste des colonnes")
If x <> "" Then colonnes = Split(x, ",")
With ActiveSheet
With .QueryTables.Add(Connection:="TEXT;" & fichier, Destination:=Range("$A$1"))
.Name = "bdd"
.FieldNames = True
.PreserveFormatting = True
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileDecimalSeparator = "."
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
.Delete
End With
tbl = Application.Index(.Cells(1).CurrentRegion.Value, Evaluate("ROW(" & 1 & ":" & .Cells(1).CurrentRegion.Rows.Count & ")"), colonnes)
.Cells(1).CurrentRegion.ClearContents
.Cells(1).Resize(UBound(tbl), UBound(tbl, 2)) = tbl
End With
End Sub
Re
•>thunder23
Le Delete te gène ?
Pas de souci
Alors, il suffisait d'être un peu curieux, non ?
Un indice: xlSkipColumn
Allez, c'est ... KADO
https://docs.microsoft.com/fr-fr/office/vba/api/excel.xlcolumndatatype
Allo!!! #94
Set destinat = IIf(.[A1] <> "", .Range("$A$" & .Cells(Rows.Count, 1).End(xlUp).Row + 2), .[A1])
With .QueryTables.Add(Connection:="TEXT;" & fichier, Destination:=destinat)
re je viens d'essayer le successif et effectivement il colle les données horizontaement c'est chiant
pourtant l'adresse de destination c'est toujours
VB:Set destinat = IIf(.[A1] <> "", .Range("$A$" & .Cells(Rows.Count, 1).End(xlUp).Row + 2), .[A1]) With .QueryTables.Add(Connection:="TEXT;" & fichier, Destination:=destinat)
Re
Allo! et le #95?