Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBA salvare file txt (csv) con zeri decimali significativi

14 views
Skip to first unread message

Inf

unread,
Jun 1, 2023, 10:57:36 AM6/1/23
to
Buon pomeriggio a tutti,

uso questo codice VBA per creare file csv/txt

Sub File_CSV()

Dim NomeFile As String
Dim TotDati As Long, RigEnd As Long
Dim ColIni As Byte, RigIni As Byte, ColEnd As Byte, i As Byte
Dim y As Long
Dim Valore

NomeFile = "Z:\Fatture.csv"
TotDati = Application.WorksheetFunction.CountA(Worksheets("Fatture").Range("A:A"))
Worksheets("Fatture").Activate

ColIni = 1
RigIni = 1
ColEnd = 4
RigEnd = TotDati

Open NomeFile For Output As #1
For y = RigIni To RigEnd
For i = ColIni To ColEnd
Valore = Cells(y, i).Value
If i = ColEnd Then
Valore = Valore & vbCrLf 'Chr(13)
Else
Valore = Valore & ";"
End If
Print #1, Valore;
Next i
Next y
Close #1

End Sub

(non uso appositamente file/salva/ CSV UTF-8 (delimitato dalla virgole) (*.csv)

purtroppo il valore 1.011,10 lo esporta come 1011,1 ovvero privo dello zero decimale;
sapreste indicarmi come "mantenerlo"?

Cordialità.
Maurizio

casanmaner

unread,
Jun 1, 2023, 11:30:49 AM6/1/23
to
Probabilmente devi "passare" i valori numeri in formato stringa dandogli la formattazione desiderata.
Es.
Valore = Cells(y, i).Value
IIf IsNumeric(Valore) Then Valore = Format(Valore, "#,00.00")


Fai una prova

Inf

unread,
Jun 1, 2023, 3:00:16 PM6/1/23
to
Semplice e perfetto
Grazie

0 new messages