Hi, I have searched a lot but find no answer. Hope someone helps me in this context.
I am using a vba code to create a text file from an excel sheet. The code works fine. But there is a number format in decimal in excel which converts as a number without a decimal place in the text file. below is the code I used.
Hope someone helps me to overcome my difficulties and tell me what to change or add to the code.
Thanks in advance
I am using a vba code to create a text file from an excel sheet. The code works fine. But there is a number format in decimal in excel which converts as a number without a decimal place in the text file. below is the code I used.
VBA Code:
Dim UsedRows As Long
Dim UsedColumns As Long
Dim R As Long, C As Long
Dim Data As Variant
'// Define a suitable file name
Open "E:\Folder\" & "TD.txt" For Output As #1
With ActiveSheet
UsedRows = .UsedRange.Rows.Count
UsedColumns = .UsedRange.Columns.Count
For R = 2 To UsedRows
For C = 1 To UsedColumns
Print #1, .Cells(R, C); "|";
Set Cell = .Cells(R, C)
If IsNumeric(Cell) Then
Data = Data & Cell.NumberFormat = "#,##0.00"
Else
Data = Data & vbTab & Cell.Value
End If
Next C
Print #1, .Cells(R, UsedColumns)
Next R
End With
Thanks in advance