Remplacement de point par virgule
Bonjour je me heurte a un problème bizarre ???
J' importe un csv en vba et je l'affiche sur une nouvelle feuille.
Je fait un peu de formatage sur ma feuille pour supprimer les lignes inutile
Jusque la tout va bien.
pour certaine colonne je me retrouve avec des points pour les chiffres je dois donc les remplacer par des virgules pour pouvoir faire une somme sur cette même colonne
Je ne trouve pas la solution
Le code complet :
Sub ImportCSV()
fic = Application.GetOpenFilename("Fichiers csv, *.csv")
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & fic _
, Destination:=Range("$A$1"))
.Name = "statement"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 65001
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 4, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
'Extraction du nom de fichier
fic = Replace(fic, ".csv", "")
For i = Len(fic) To 1 Step -1
If Mid(fic, i, 1) = "-" Then Exit For
Next i
fic = Right(fic, Len(fic) - i)
ActiveSheet.Name = fic
ActiveWindow.SmallScroll Down:=3
'Suppresion
Dim nbligne As Integer
nbligne = Cells.SpecialCells(xlCellTypeLastCell).Row
For i = nbligne To 1 Step -1
If IsEmpty(Cells(i, 6)) Then Cells(i, 1).EntireRow.Delete
Next i
'Mise en forme
Dim nbl As String
nbl = Range("A65536").End(xlUp).Row
' Range("A1:N" + nbl).Select
'Range("N" & nbl).Activate
'ActiveSheet.QueryTables("statement").Delete
' ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$N$" + nbl), , xlYes).Name = _
"Tableau1"
'ActiveSheet.Range("Tableau1[#All]").Select
'autofit colonnes
For i = 1 To 16
Columns(i).AutoFit
Next i
Columns("A:A").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'format monétaire cellulle
Columns("H:H").Select
Range("H773").Activate
Selection.NumberFormat = "#,##0.00 [$$-fr-CA]"
Set plage = Range("H2:O" & Range("A65536").End(xlUp).Row)
For Each c In plage
c.Value = Replace(c, ".", ",")
Next c
End SubMerci pour les retours si il y en a
bonjour,
peux-tu mettre ton fichier csv ?
Bonjour,
Bonjour h2so4;
Pour traiter un csv à partir d'Excel 2016 tu n'as pas besoin de VBA.
Utilise Récupérer et transformer (Power Query). C'est simple (et rapide).
Bon cela demande un petit apprentissage mais…
Comme demandé par h2so4, joins ton fichier.
Cdlt.
Bonsoir pcpunch59,
Essaies en remplacer le bout de code :
'format monétaire cellulle
Columns("H:H").Select
Range("H773").Activate
Selection.NumberFormat = "#,##0.00 [$$-fr-CA]"
Set plage = Range("H2:O" & Range("A65536").End(xlUp).Row)
For Each c In plage
c.Value = Replace(c, ".", ",")
Next cpar :
'format monétaire cellulle
'Columns("H:H").Select
'Range("H773").Activate
'Selection.NumberFormat = "#,##0.00 [$$-fr-CA]"
Set plage = Range("H2:O" & Range("A65536").End(xlUp).Row)
Dim dbl as double, str as string
For Each c In plage.cells
str = Replace(c.Value, ".", ",")
if IsNumeric(str) then
dbl = CDbl(str)
c.Value =dbl
c.NumberFormat = "#0.00"
endif
Next c