Laurentsavoie
XLDnaute Nouveau
Bonjour !
Je fais une récupération d'un fichier texte grace à la macro ci-dessous. Le fichier texte est créé grace à un transfert de données à partir d'un serveur ISéries nouveau nom pour les as400 de IBM.
mon fichier texte contient des chiffres qui ont un . pour séparer les milliers et une , pour les décimales.
Si je lance une recherche remplacement à la main pour remplacer les . par rien ça fonctionne bien et mes virgules restent bien en place. Mais si j'intègre cette fonction dans ma macro les virgules sont également remplacées par rein.
comment résoudre ce problème ?
Ma macro :
😕
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\temp\Transfertas400.", _
Destination:=Range("$A$1"))
.Name = "Transfertas400."
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(2, 6, 3, 31, 1, 7, 2, 9, 47, 7, 79)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
ActiveWindow.SmallScroll Down:=-9
Cells.Select
ActiveWorkbook.Worksheets("Feuil4").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Feuil4").Sort.SortFields.Add Key:=Range("B1:B1215" _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Feuil4").Sort
.SetRange Range("A1:K1215")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWindow.SmallScroll Down:=-3
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Columns("C:C").Select
Selection.Delete Shift:=xlToLeft
Columns("D😀").Select
Selection.ClearContents
Selection.Delete Shift:=xlToLeft
Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll Down:=63
Columns("F:F").Select
Range("F64").Activate
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll Down:=-72
Range("A1").Select
Cells.Replace What:=".", Replacement:="", LookAt:=xlPart, SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
ActiveWindow.SmallScroll Down:=-15
Range("A1").Select
End Sub
Je fais une récupération d'un fichier texte grace à la macro ci-dessous. Le fichier texte est créé grace à un transfert de données à partir d'un serveur ISéries nouveau nom pour les as400 de IBM.
mon fichier texte contient des chiffres qui ont un . pour séparer les milliers et une , pour les décimales.
Si je lance une recherche remplacement à la main pour remplacer les . par rien ça fonctionne bien et mes virgules restent bien en place. Mais si j'intègre cette fonction dans ma macro les virgules sont également remplacées par rein.
comment résoudre ce problème ?
Ma macro :
😕
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\temp\Transfertas400.", _
Destination:=Range("$A$1"))
.Name = "Transfertas400."
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(2, 6, 3, 31, 1, 7, 2, 9, 47, 7, 79)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
ActiveWindow.SmallScroll Down:=-9
Cells.Select
ActiveWorkbook.Worksheets("Feuil4").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Feuil4").Sort.SortFields.Add Key:=Range("B1:B1215" _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Feuil4").Sort
.SetRange Range("A1:K1215")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWindow.SmallScroll Down:=-3
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Columns("C:C").Select
Selection.Delete Shift:=xlToLeft
Columns("D😀").Select
Selection.ClearContents
Selection.Delete Shift:=xlToLeft
Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll Down:=63
Columns("F:F").Select
Range("F64").Activate
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll Down:=-72
Range("A1").Select
Cells.Replace What:=".", Replacement:="", LookAt:=xlPart, SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
ActiveWindow.SmallScroll Down:=-15
Range("A1").Select
End Sub