How to avoid scientific notation when converting to string

bar_ba_dos

New Member
Joined
Nov 20, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a worksheet that contains data such as shown below:
Excel.JPG


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:
Excel2.JPG


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.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
See if this works:
Rich (BB code):
fileLine = sCat(Application.Trim(Range(ws.Cells(rLoop, 1), ws.Cells(rLoop, maxCols + 1))), ",")
 
Upvote 0
See if this works:
Rich (BB code):
fileLine = sCat(Application.Trim(Range(ws.Cells(rLoop, 1), ws.Cells(rLoop, maxCols + 1))), ",")

Thanks it nearly worked. There is one instance where the figure still shows in scientific notation. The remaining figures are showing exactly as required.

Output.JPG


Why would that be?
 

Attachments

  • Output.JPG
    Output.JPG
    127.8 KB · Views: 6
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,205
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top