Re : Récupperer des données fichier txt dans un fichier xls
Effectivement ca vien d'un programme, mais fait maison par un collegue.
Par contre j'ai cette macro pour un problem similaire . Pense tu kel soit adaptable a mes fichier texte avec comme séparateur: 205************,206************,207************,215************,216************,2187************.
VOICI LA MACRO ET ENCORE MERCI.
Option Explicit
Sub Bouton1_QuandClic()
ActiveSheet.Protect Password:="GRATC", UserInterfaceOnly:=True
Range("A2:G65000").ClearContents
Dim chemin As String
Dim fichier As String
Dim ligne As Integer
Dim i As Integer, x As Integer, j As Integer, k As Integer
Dim tablosplit As Variant
Dim valeur As String
Dim tablores()
Dim tabloL As Variant
Dim tablo()
tabloL = Range("l2:l" & Range("l65536").End(xlUp).Row)
chemin = "C:\test2\FICHIERS\"
fichier = Dir(chemin & "*.txt")
ligne = 2
Do While fichier <> ""
Open chemin & fichier For Input As #1
Do While Not EOF(1)
Line Input #1, valeur
x = x + 1
ReDim Preserve tablores(1 To x)
tablores(x) = valeur
Loop
Close #1
fichier = Dir
Loop
x = 0
ReDim tablo(1 To 11, 1 To 1)
For i = 1 To UBound(tablores)
Select Case Left(tablores(i), 3)
Case "! 5", "! 6", "! 7":
tablosplit = Split(tablores(i), "!")
x = x + 1
For j = 0 To 10
ReDim Preserve tablo(1 To 11, 1 To x)
tablo(j + 1, x) = tablosplit(j)
Next j
For k = 1 To UBound(tabloL)
If Val(Trim(tablo(3, x))) = tabloL(k, 1) Then
tablosplit = Split(tablores(i + 1), "!")
x = x + 1
For j = 0 To 10
ReDim Preserve tablo(1 To 11, 1 To x)
tablo(j + 1, x) = tablosplit(j)
Next j
End If
Next k
End Select
Next i
For i = 1 To UBound(tablo, 2)
Cells(ligne, 1) = tablo(2, i)
Cells(ligne, 2) = tablo(3, i) 'tarif
Cells(ligne, 3) = tablo(4, i)
Cells(ligne, 4) = tablo(8, i)
Cells(ligne, 5) = tablo(9, i)
Cells(ligne, 6) = tablo(10, i)
Cells(ligne, 7) = tablo(11, i)
ligne = ligne + 1
Next i
End Sub