Converting Excel File to CSV
Hi VBExpress Nation!
I am hopeful if a second pair eyes will help out: I am trying to capture cells in my spreadsheet that may have commas and I need to keep the content of that cell together. My code is below
Code:
Sub Create CSVDim fname as strong
Dim LText as String
Dim CSText as Variant
Dim myRange as Range, I, j
fname = ThisWorkbook.Path & “ExportData” & “.csv”
Open fname for Output as #1
With Active Sheet
Set myRange = .Range(“Report”)
For I= 1 to myRange.Rows.Count
For j = 1 to myRange.Columns.Count
If Instr(myRng.Cells(i,j),”,”)> 0 then
CSText = “‘“ & myRange.Cells(I,j) & “‘“
LText = LText & CSText
CSText = “”
else
LText = IIf(j=1, “”,LText & “,”) & myRange.Cells(I,j)
End If
Next j
print #1, LText
Next I
End With
Msgbox “All complete!”, vbInformation, “Data to CSV Format”
End Sub
Thanks in advance to everyone for their help.
Slice