OVH Cloud OVH Cloud

des décimales dans un export .txt

3 réponses
Avatar
jean michel
Bonjour à toutes et tous

cette macro exporte un fichier excel en .txt ; mais je ne sais pas comment
je pourrais exporter des chiffres apres la virgule.

Merci de votre aide estivale !
_________________________________________________________
9976 DAVY ; 250,25; prime... ; 4352; 310500; 301,25
9776 ;DAVY; 250 ;PRIME DE COCKTAIL; 4352 ; 310500 ; 301

Sub ExpRange1()
Dim ExpRng As Range
Set ExpRng = ActiveCell.CurrentRegion
FirstCol = ExpRng.Columns(1).Column
LastCol = FirstCol + ExpRng.Columns.Count - 1
FirstRow = ExpRng.Rows(1).Row
LastRow = FirstRow + ExpRng.Rows.Count - 1

Open ThisWorkbook.Path & "\P2aINTEGRER.txt" For Output As #1
For r = FirstRow To LastRow
For c = FirstCol To LastCol
data = ExpRng.Cells(r, c).Value
If data = "" Then data = ""
If IsNumeric(data) Then data = Val(data)
If c <> LastCol Then
Print #1, data;
'commenter la ligne ci-dessous pour conserver le délimiteur par défaut
Print #1, ";"; 'ici le délimiteur personnalisé
Else
Print #1, data
End If
Next c
Next r
Close #1
End Sub

3 réponses

Avatar
Clément Marcotte
Bonjour,

Val() plante quand on a la virgule comme séparateur décimal.

Essaie en remplaçant val() par Csng() (Convert Single (7 chiffres
significatifs)) ou Cdbl() (Convert Double (15 chiffres significatifs))


"jean michel" a écrit dans le message de
news:3f28e979$0$25431$
Bonjour à toutes et tous

cette macro exporte un fichier excel en .txt ; mais je ne sais pas
comment

je pourrais exporter des chiffres apres la virgule.

Merci de votre aide estivale !
_________________________________________________________
9976 DAVY ; 250,25; prime... ; 4352; 310500; 301,25
9776 ;DAVY; 250 ;PRIME DE COCKTAIL; 4352 ; 310500 ; 301

Sub ExpRange1()
Dim ExpRng As Range
Set ExpRng = ActiveCell.CurrentRegion
FirstCol = ExpRng.Columns(1).Column
LastCol = FirstCol + ExpRng.Columns.Count - 1
FirstRow = ExpRng.Rows(1).Row
LastRow = FirstRow + ExpRng.Rows.Count - 1

Open ThisWorkbook.Path & "P2aINTEGRER.txt" For Output As #1
For r = FirstRow To LastRow
For c = FirstCol To LastCol
data = ExpRng.Cells(r, c).Value
If data = "" Then data = ""
If IsNumeric(data) Then data = Val(data)
If c <> LastCol Then
Print #1, data;
'commenter la ligne ci-dessous pour conserver le délimiteur par
défaut

Print #1, ";"; 'ici le délimiteur personnalisé
Else
Print #1, data
End If
Next c
Next r
Close #1
End Sub




Avatar
jean michel
merci du tuyau ; je teste !

"Clément Marcotte" a écrit dans le message
de news:%
Bonjour,

Val() plante quand on a la virgule comme séparateur décimal.

Essaie en remplaçant val() par Csng() (Convert Single (7 chiffres
significatifs)) ou Cdbl() (Convert Double (15 chiffres significatifs))


"jean michel" a écrit dans le message de
news:3f28e979$0$25431$
Bonjour à toutes et tous

cette macro exporte un fichier excel en .txt ; mais je ne sais pas
comment

je pourrais exporter des chiffres apres la virgule.

Merci de votre aide estivale !
_________________________________________________________
9976 DAVY ; 250,25; prime... ; 4352; 310500; 301,25
9776 ;DAVY; 250 ;PRIME DE COCKTAIL; 4352 ; 310500 ; 301

Sub ExpRange1()
Dim ExpRng As Range
Set ExpRng = ActiveCell.CurrentRegion
FirstCol = ExpRng.Columns(1).Column
LastCol = FirstCol + ExpRng.Columns.Count - 1
FirstRow = ExpRng.Rows(1).Row
LastRow = FirstRow + ExpRng.Rows.Count - 1

Open ThisWorkbook.Path & "P2aINTEGRER.txt" For Output As #1
For r = FirstRow To LastRow
For c = FirstCol To LastCol
data = ExpRng.Cells(r, c).Value
If data = "" Then data = ""
If IsNumeric(data) Then data = Val(data)
If c <> LastCol Then
Print #1, data;
'commenter la ligne ci-dessous pour conserver le délimiteur par
défaut

Print #1, ";"; 'ici le délimiteur personnalisé
Else
Print #1, data
End If
Next c
Next r
Close #1
End Sub







Avatar
Esteban
Bonjour ,
Val( ) utilise le point comme séparateur de décimale.
Utile la fonction CStr( ) qui se base sur les paramètres régionaux de ton
ordinateur.
Ainsi sur un poste configuré en Français CStr("10,532") renvoie 10,532.

Cordialement,
Esteban

"jean michel" a écrit dans le message de
news:3f2900b8$0$25427$
merci du tuyau ; je teste !

"Clément Marcotte" a écrit dans le message
de news:%
Bonjour,

Val() plante quand on a la virgule comme séparateur décimal.

Essaie en remplaçant val() par Csng() (Convert Single (7 chiffres
significatifs)) ou Cdbl() (Convert Double (15 chiffres significatifs))


"jean michel" a écrit dans le message de
news:3f28e979$0$25431$
Bonjour à toutes et tous

cette macro exporte un fichier excel en .txt ; mais je ne sais pas
comment

je pourrais exporter des chiffres apres la virgule.

Merci de votre aide estivale !
_________________________________________________________
9976 DAVY ; 250,25; prime... ; 4352; 310500; 301,25
9776 ;DAVY; 250 ;PRIME DE COCKTAIL; 4352 ; 310500 ; 301

Sub ExpRange1()
Dim ExpRng As Range
Set ExpRng = ActiveCell.CurrentRegion
FirstCol = ExpRng.Columns(1).Column
LastCol = FirstCol + ExpRng.Columns.Count - 1
FirstRow = ExpRng.Rows(1).Row
LastRow = FirstRow + ExpRng.Rows.Count - 1

Open ThisWorkbook.Path & "P2aINTEGRER.txt" For Output As #1
For r = FirstRow To LastRow
For c = FirstCol To LastCol
data = ExpRng.Cells(r, c).Value
If data = "" Then data = ""
If IsNumeric(data) Then data = Val(data)
If c <> LastCol Then
Print #1, data;
'commenter la ligne ci-dessous pour conserver le délimiteur par
défaut

Print #1, ";"; 'ici le délimiteur personnalisé
Else
Print #1, data
End If
Next c
Next r
Close #1
End Sub