ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Comma Delimited-need comma at beginnng & end (https://www.excelbanter.com/excel-discussion-misc-queries/169243-comma-delimited-need-comma-beginnng-end.html)

Tattoo

Comma Delimited-need comma at beginnng & end
 
How do you do a comma delimited file that has a comma in the first cell and
the last cell? Whenever I put a comma in the first and last column, it puts
quotation marks around the comma.
--
Tattoo

joel

Comma Delimited-need comma at beginnng & end
 
Here is code that I have used before (slighly modified) that a I have posted
a number of times before. It always gives great results. Modify the 2nd and
3rd lines as required.


Sub WriteCSV()
Const MyPath = "C:\temp\"
Const WriteFileName = "text.csv"

Const Delimiter = ","
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

Set fswrite = CreateObject("Scripting.FileSystemObject")
'open files
WritePathName = MyPath + WriteFileName
fswrite.CreateTextFile WritePathName
Set fwrite = fswrite.GetFile(WritePathName)
Set tswrite = fwrite.OpenAsTextStream(ForWriting, TristateUseDefault)

LastRow = Cells(Rows.Count, "A").End(xlUp).Row

For RowCount = 1 To LastRow
LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Column
For ColCount = 1 To LastCol
If ColCount = 1 Then
OutputLine = "," & Cells(RowCount, ColCount)
Else
OutputLine = OutputLine & Delimiter & Cells(RowCount, ColCount)
End If
Next ColCount
OutputLine = OutputLine & ","
tswrite.writeline OutputLine
Next RowCount

tswrite.Close

Exit Sub
End Sub


"Tattoo" wrote:

How do you do a comma delimited file that has a comma in the first cell and
the last cell? Whenever I put a comma in the first and last column, it puts
quotation marks around the comma.
--
Tattoo


Dave Peterson

Comma Delimited-need comma at beginnng & end
 
How about putting something else in that first column?

I like to use a formula that makes the cell look blank:
=""



Tattoo wrote:

How do you do a comma delimited file that has a comma in the first cell and
the last cell? Whenever I put a comma in the first and last column, it puts
quotation marks around the comma.
--
Tattoo


--

Dave Peterson


All times are GMT +1. The time now is 01:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com