bar_ba_dos
New Member
- Joined
- Nov 20, 2023
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hi All,
I have a worksheet that contains data such as shown below:
I need to write this to a csv file.
The .SaveAs method isn't working for me as this would create 2 trailing commas for row 2.
My approach therefore is:
- For each row I determine the last column containing data;
- Then I create a string of all cells in that row;
- That string is written to a file.
The relevant part of the code looks like:
where sCat is the following function:
The data in my output csv file looks like:
Question - how do I avoid the number 0.0834859097545727 to end up with scientific notation in my csv file? Ideally I don't want to change the formatting of my cells on the worksheet.
I have a worksheet that contains data such as shown below:
I need to write this to a csv file.
The .SaveAs method isn't working for me as this would create 2 trailing commas for row 2.
My approach therefore is:
- For each row I determine the last column containing data;
- Then I create a string of all cells in that row;
- That string is written to a file.
The relevant part of the code looks like:
VBA Code:
fileLine = sCat(Range(ws.Cells(rLoop, 1), ws.Cells(rLoop, maxCols + 1)), ",")
Print #fileNumber, fileLine
where sCat is the following function:
VBA Code:
Function sCat(vP As Variant, delim As String) As String
' Concatenate all cells in a range, delimited by delim.
Dim v
Dim delim2 As String
For Each v In vP
sCat = sCat & delim2 & v
delim2 = delim
Next v
End Function
The data in my output csv file looks like:
Question - how do I avoid the number 0.0834859097545727 to end up with scientific notation in my csv file? Ideally I don't want to change the formatting of my cells on the worksheet.