im practicing vba and the code below writes data from the excel sheet to a newly created csv. Column A shows the ISBN number, column B shows the last name and column c shows the first name. The data in the cells are not formatted with wrap text
however, when i open the newly created csv in excel, the cells are automatically formatted with wrap text. This causes the data for each row to not be in a single line when i open the csv in notepad.
How do i remove the auto wrap text such that my data will appear in a single line when i open the csv in notepad?
however, when i open the newly created csv in excel, the cells are automatically formatted with wrap text. This causes the data for each row to not be in a single line when i open the csv in notepad.
How do i remove the auto wrap text such that my data will appear in a single line when i open the csv in notepad?
VBA Code:
Sub writetextfile()
Dim filepath As String
Dim celldata As String
Dim lastcol As Long
Dim lastrow As Long
lastcol = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Column
lastrow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
celldata = ""
filepath = application.defaultfilepath & "\auth.csv"
Open filepath For Output As #2
For i = 1 To lastrow
For j = 1 To lastcol
If j = lastcol Then
celldata = celldata + Trim(Cells(i, j).Value)
Else
celldata = celldata + Trim(Cells(i, j).Value) + ","
End If
Next j
Write #2, celldata
celldata = ""
Next i
Close #2
MsgBox "done"
End Sub