Spliter une chaine avec plusieurs trigger
V
Bonjour,
J'ai a nouveau besoin de votre aide.
J'importe un fichier CSV, je Split la chaîne avec les ",".... jusque là tout va bien.
Maintenant, j'aimerai pouvoir également spliter avec les "/"
exemple:
2017-08-29 04:44:21,182,,5,0,95/200M, 48, 58, 100/XmD, 25, 0.005/PVM, 0.0020, 0.008/PVE, 0.0010
2017-08-29 04:44:21 182 5 0 95 200 MD 48 58 100 XmD 25 0.005 PVM ....
encore merci
Vincent
Sub LireCsv(NomFichier)
Dim Ar() As String
Dim LastLig As Long
Feuil3.Select
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlManual
End With
Dim NbJours As Long, DatePlusCinq As Date
LastLig = Cells(Rows.Count, 4).End(xlUp).Row + 1 'LastLig est la dernière ligne remplie du fichier csv ouvert
first = 0
Sep = ","
Lig = LastLig
' -----------------------------------------
'On Error Resume Next
Open NomFichier For Input As #1
Do While Not EOF(1)
Line Input #1, Chaine
Ar = Split(Chaine, Sep)
If first <> 0 Then
Col = 4
If Lig <> 10 Then
On Error Resume Next
For X = LBound(Ar) To UBound(Ar)
If Col = 4 Then
Cells(Lig, Col).Value = CStr(Ar(X))
d = DateSerial(Year(Cells(Lig, Col).Value), Month(Cells(Lig, Col).Value), Day(Cells(Lig, Col).Value)) + TimeSerial(Hour(Cells(Lig, Col).Value), Minute(Cells(Lig, Col).Value), Second(Cells(Lig, Col).Value))
Cells(Lig, Col).Value = d
Cells(Lig, Col).NumberFormat = "dd/mm/yyyy hh:mm:ss"
Else
Cells(Lig, Col).Value = CStr(Ar(X))
End If
Col = Col + 1
Next
End If
Else
first = first + 1
Lig = Lig - 1
End If
Lig = Lig + 1
Loop
Close #1
' -----------------------------------------
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.CutCopyMode = False
.Goto [A1], True
End With
End Sub
Bonjour
remplace ton instruction split par celle-ci (remplace le / par ton séparateur avant le split)
Ar = Split(Replace(Chaine, "/", Sep), Sep)
V