bonjour a tous,
j'ai un petit soucis au niveau de la formation de mon fichier csv, voici mon code :
Quand je crée mon .csv, je ne comprends pas, les colonnes que j'avais traité pour passer du format date a texte ( 2013-12-11 avec colonne format texte) , se réinitialise et revienne comme a l'état initial(11/12/2013 avec colonne format date, comme si je ne les avait pas traités.
Savez-vous pourquoi cela fait ça et il y a un moyen de contrer sa ?
Je vous remercie par avance
Julien
j'ai un petit soucis au niveau de la formation de mon fichier csv, voici mon code :
Code:
Sub Traitement()
'- Déclaration des variables
Dim dl As Integer, dc As Integer, lf As Integer
Dim r As Range
Dim f1 As Worksheet, f2 As Worksheet, f3 As Worksheet, f4 As Worksheet
Dim c As Variant, k As Variant
Dim dD As Object, dM As Object, dP As Object
Dim T As Long
Dim I As Long
Dim V As Double
'- On enregistre les onglets
Set f1 = Feuil1: Set f2 = Feuil11: Set f3 = Feuil2
'- On désactive les application
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'- On débute la procédure
On Error Resume Next
Worksheets("traitement").Delete
'On Error GoTo 0
'- Copie de la feuille PO-PB en dernière position et renomme par traitement
f1.Copy After:=Worksheets(Worksheets.Count)
Set f4 = Worksheets(Worksheets.Count)
f4.Name = "traitement"
'- On copie la ligne 1 de la bdd
With f2
.Range(.Cells(1, 1), .Cells(1, .Cells.Find("*", , , , xlByColumns, xlPrevious).Column)).Copy f4.Cells(1, 1)
End With
'- On joue avec la feuille traitement (f4)
With f4
.Activate
ActiveWindow.FreezePanes = False
With .Rows("1")
.EntireRow.AutoFit
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
End With
.AutoFilterMode = False
dl = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
dc = .Cells.Find("*", , , , xlByColumns, xlPrevious).Column
Set r = .Range(.Cells(2, 1), .Cells(dl, dc))
r.Copy: .Cells(2, 1).PasteSpecial , Paste:=xlPasteValues: Application.CutCopyMode = False
Set dD = CreateObject("Scripting.Dictionary"): Set dM = CreateObject("Scripting.Dictionary"): Set dP = CreateObject("Scripting.Dictionary")
For Each c In r
If Left(c.Value, 1) = "/" Or c.Value = 0 Then
c.ClearContents
ElseIf IsDate(c) Then dD(c.Column) = ""
ElseIf InStr(1, c.Text, "€") > 0 Then dM(c.Column) = ""
ElseIf Right(c.Text, 1) = "%" Then dM(c.Column) = "": c.Value = c.Value * 100
ElseIf Left(c.Value, 1) = "x" Or Left(c.Value, 1) = "X" Or Left(c.Value, 1) = "w" Or Left(c.Value, 1) = "o" Then c.Value = 1
ElseIf Left(c.Value, 1) = "n" Or Left(c.Value, 1) = "N" Then c.Value = 0
End If
Next c
For Each k In dD.Keys
For Each c In .Range(.Cells(2, k), .Cells(dl, k))
If c.Value <> "" And Not IsDate(c.Value) Then c.ClearContents
Next c
.Range(.Cells(2, k), .Cells(dl, k)).NumberFormat = "@"
For Each c In .Range(.Cells(2, k), .Cells(dl, k))
If c.Value <> "" Then c.Value = Format(c.Value, "yyyy-mm-dd")
Next c
.Range(.Cells(2, k), .Cells(dl, k)).NumberFormat = "General"
Next k
For Each k In dM.Keys: .Range(.Cells(2, k), .Cells(dl, k)).NumberFormat = "0.00": Next k
Columns("A:A").Insert Shift:=xlToLeft
.Range("A" & .Range("A" & Rows.Count).End(xlUp).Row).Offset(0, 0).Value = "id_dossier"
For I = 2 To 770
Cells(I, 1).Value = V + 1
V = V + 1
Next
End With
'- On réactive les application
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
For Each ws In Worksheets
Application.DisplayAlerts = False
If ws.Name <> "traitement" Then ws.Delete
Next
Application.DisplayAlerts = True
ActiveWorkbook.SaveAs Filename:="Traitement", FileFormat:=xlCSV, CreateBackup:=False, local:=True
End Sub
Quand je crée mon .csv, je ne comprends pas, les colonnes que j'avais traité pour passer du format date a texte ( 2013-12-11 avec colonne format texte) , se réinitialise et revienne comme a l'état initial(11/12/2013 avec colonne format date, comme si je ne les avait pas traités.
Savez-vous pourquoi cela fait ça et il y a un moyen de contrer sa ?
Je vous remercie par avance
Julien